HoverRace  2.0
InternetRoom.h
Go to the documentation of this file.
1 #ifdef HR_LEGACY_BUILD
2 // InternetRoom.h
3 //
4 //
5 // Copyright (c) 1995-1998 - Richard Langlois and Grokksoft Inc.
6 //
7 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
8 // you may not use this file except in compliance with the License.
9 //
10 // A copy of the license should have been attached to the package from which
11 // you have taken this file. If you can not find the license you can not use
12 // this file.
13 //
14 //
15 // The author makes no representations about the suitability of
16 // this software for any purpose. It is provided "as is" "AS IS",
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
18 // implied.
19 //
20 // See the License for the specific language governing permissions
21 // and limitations under the License.
22 //
23 
24 #pragma once
25 
26 #include <WINSOCK.h>
27 
28 #include <string>
29 
30 #include "../../engine/Parcel/TrackBundle.h"
31 
32 #include "TrackSelectDialog.h"
33 #include "NetworkSession.h"
34 #include "GifDecoder.h"
35 #include "RoomList.h"
36 
37 namespace HoverRace {
38 namespace Client {
39 
40 class InternetRequest
41 {
42  protected:
43  time_t mStartTime;
44  BOOL mBinMode; // use Bin buffer and Bin sending mode"referer request"
45 
46  SOCKET mSocket;
47  std::string mRequest;
48  std::string mBuffer;
49 
50  char *mBinBuffer;
51  int mBinIndex;
52 
53  void Close();
54  BOOL Working() const;
55 
56  public:
57  InternetRequest();
58  ~InternetRequest();
59 
60  void SetBin();
61 
62  BOOL Send(HWND pWindow, unsigned long pIP, unsigned int pPort, const char *pURL, const char *pCoookie = NULL);
63  void Clear(); // Abort and clean
64  // return TRUE if some processing was done
65  BOOL ProcessEvent(WPARAM pWParam, LPARAM pLParam);
66 
67  const char *GetBuffer() const;
68  const char *GetBinBuffer(int &pSize) const;
69 
70  BOOL IsReady() const;
71 };
72 
73 class InternetRoom
74 {
75  public:
76  enum {
77  eMaxClient = 300,
78  eMaxGame = 100,
79  eMaxChat = 50,
80  eMaxPlayerGame = 16
81  };
82 
83  enum {
84  eChatModified = 1,
85  eUsersModified = 2,
86  eGamesModified = 4
87  };
88 
89  protected:
90 
91  class Client
92  {
93  public:
94  BOOL mValid;
95  std::string mName;
96  int mGame;
97  int mMajorID;
98  int mMinorID;
99 
100  };
101 
102  class Game
103  {
104  public:
105 
106  BOOL mValid;
107  int mId;
108  MR_TrackAvail mAvailCode;
109  std::string mName;
110  std::string mTrack;
111  int mNbLap;
112  BOOL mAllowWeapons;
113  int mNbClient;
114  int mClientList[eMaxPlayerGame];
115  std::string mIPAddr;
116  unsigned mPort;
117 
118  };
119 
120  static InternetRoom *mThis;
121 
122  RoomListPtr roomList;
123 
124  std::string mMainServer;
125 
126  int mCurrentUserIndex;
127  int mCurrentUserId;
128  int mCurrentGameIndex;
129  int mCurrentGameId;
130 
131  std::string mUser;
132 
133  Client mClientList[eMaxClient];
134  Game mGameList[eMaxGame];
135 
136  std::string mChatBuffer;
137 
138  int mLastRefreshTimeStamp;
139 
140  HWND mModelessDlg;
141 
142  // Temporary data
143  HANDLE mCurrentLocateRequest;
144  char mHostEnt[MAXGETHOSTSTRUCT];
145  std::string mNetOpString;
146  std::string mNetOpRequest;
147  NetworkSession *mSession;
148  VideoServices::VideoBuffer *mVideoBuffer;
149  int mNbSuccessiveRefreshTimeOut;
150 
151  InternetRequest mOpRequest;
152  InternetRequest mChatRequest;
153  InternetRequest mRefreshRequest;
154  InternetRequest mBannerRequest;
155  InternetRequest mClickRequest;
156 
157  Util::OS::timestamp_t lastMessageReceivedSoundTs;
158 
159  WNDPROC oldBannerProc;
160  GifDecoder mBanner;
161  int mCurrentBannerIndex;
162 
163  bool checkUpdates;
164 
165  std::ofstream *chatLog;
166 
167  /*
168  static BOOL CALLBACK AskParamsCallBack(HWND pWindow, UINT pMsgId, WPARAM pWParam, LPARAM pLParam);
169  */
170  static BOOL CALLBACK RoomCallBack(HWND pWindow, UINT pMsgId, WPARAM pWParam, LPARAM pLParam);
171  static BOOL CALLBACK BannerCallBack(HWND pWindow, UINT pMsgId, WPARAM pWParam, LPARAM pLParam);
172  static BOOL CALLBACK NetOpCallBack(HWND pWindow, UINT pMsgId, WPARAM pWParam, LPARAM pLParam);
173  static BOOL CALLBACK FastNetOpCallBack(HWND pWindow, UINT pMsgId, WPARAM pWParam, LPARAM pLParam);
174  static BOOL CALLBACK GetAddrCallBack(HWND pWindow, UINT pMsgId, WPARAM pWParam, LPARAM pLParam);
175 
176  BOOL AskRoomParams(HWND pParentWindow, BOOL pShouldRecheckServer);
177  /*
178  BOOL LocateServers(HWND pWindow, BOOL pShouldRecheckServer);
179  */
180  BOOL AddUserOp(HWND pParentWindow);
181  BOOL DelUserOp(HWND pParentWindow, BOOL pFastMode = FALSE);
182  BOOL AddGameOp(HWND pParentWindow, const char *pGameName, const char *pTrackName, int pNbLap, char pGameOpts, unsigned pPort);
183  BOOL DelGameOp(HWND pParentWindow);
184  BOOL JoinGameOp(HWND pParentWindow, int pGameIndex);
185  BOOL LeaveGameOp(HWND pParentWindow);
186  BOOL AddMessageOp(HWND pParentWindow, const char *pMessage, int pNbHours = 0, int lNbMinutes = 0);
187 
188  void SelectGameForUser(HWND pWindow);
189  void RefreshGameList(HWND pWindow);
190  void RefreshGameSelection(HWND pWindow);
191  void RefreshUserList(HWND pWindow);
192  void RefreshChatOut(HWND pWindow);
193 
194  void PlayMessageReceivedSound(HWND wnd);
195 
196  static BOOL VerifyError(HWND pParentWindow, const char *pAnswer);
197 
198  BOOL ParseState(const char *pAnswer);
199 
200  void OpenChatLog();
201  void AddChatLine(const char *pText, bool neverLog=false);
202 
203  int LoadBanner(HWND pWindow, const char *pBuffer, int pBufferLen);
204  int RefreshBanner(HWND pWindow); // Return next refresh time
205 
206  static void TrackOpenFailMessageBox(HWND parent, const std::string &name, const std::string &details);
207 
208  public:
209  InternetRoom(const std::string &pMainServer, bool mustCheckUpdates);
210  ~InternetRoom();
211 
212  RoomListPtr GetRoomList() const { return roomList; }
213 
214  BOOL DisplayChatRoom(HWND pParentWindow, NetworkSession *pSession, VideoServices::VideoBuffer *pVideoBuffer, BOOL pShouldRecheckServer);
215 
216  // Modelless.. do not use for the moment
217  /*
218  BOOL DisplayModeless( HWND pParentWindow, MR_NetworkSession* pSession, VideoServices::VideoBuffer* pVideoBuffer );
219  BOOL IsDisplayed()const;
220  */
221 
222 };
223 
224 BOOL MR_SendRaceResult(HWND pParentWindow, const char *pTrack,
225  int pBestLapTime, int pMajorID, int pMinorID, const char *pAlias,
226  unsigned int pTrackSum, int pHoverModel, int pTotalTime,
227  int pNbLap, int pNbPlayer, HoverRace::Client::RoomListPtr roomList);
228 
229 /*
230 BOOL MR_SendLadderResult(HWND pParentWindow, const char *pWinAlias,
231  int pWinMajorID, int pWinMinorID, const char *pLoseAlias,
232  int pLoseMajorID, int pLoseMinorID, const char *pTrack, int pNbLap);
233 */
234 
235 } // namespace Client
236 } // namespace HoverRace
237 #endif
MR_DllDeclare void Close()
Definition: SoundServer.cpp:559
std::shared_ptr< RoomList > RoomListPtr
Definition: RoomList.h:96
MR_TrackAvail
Definition: TrackBundle.h:45
Definition: Announcement.h:24
MR_Int64 timestamp_t
Definition: OS.h:55