Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

NetworkSyncManager.h

Go to the documentation of this file.
00001 /* NetworkSyncManager - Uses ezsockets for primitive song syncing and score reporting. */ 00002 00003 #ifndef NetworkSyncManager_H 00004 #define NetworkSyncManager_H 00005 00006 #include "PlayerNumber.h" 00007 #include "Difficulty.h" 00008 #include <queue> 00009 00010 class LoadingWindow; 00011 00012 const int NETPROTOCOLVERSION=1; 00013 const int NETMAXBUFFERSIZE=1020; //1024 - 4 bytes for EzSockets 00014 const int NETNUMTAPSCORES=8; 00015 00016 enum NSCommand 00017 { 00018 NSCPing = 0, 00019 NSCPingR, //1 00020 NSCHello, //2 00021 NSCGSR, //3 00022 NSCGON, //4 00023 NSCGSU, //5 00024 NSCSU, //6 00025 NSCCM, //7 00026 NSCRSG, //8 00027 NSCUUL, //9 00028 NSCSMS, //10 00029 NSCUPOpts, //11 00030 NSCSMOnline, //12 00031 NUM_NS_COMMANDS 00032 }; 00033 00034 const NSCommand NSServerOffset = (NSCommand)128; 00035 00036 struct EndOfGame_PlayerData 00037 { 00038 int name; 00039 int score; 00040 int grade; 00041 Difficulty difficulty; 00042 int tapScores[NETNUMTAPSCORES]; //This will be a const soon enough 00043 CString playerOptions; 00044 }; 00045 00046 enum NSScoreBoardColumn 00047 { 00048 NSSB_NAMES=0, 00049 NSSB_COMBO, 00050 NSSB_GRADE, 00051 NUM_NSSB_CATEGORIES 00052 }; 00053 #define FOREACH_NSScoreBoardColumn( sc ) FOREACH_ENUM( NSScoreBoardColumn, NUM_NSSB_CATEGORIES, sc ) 00054 00055 class EzSockets; 00056 class StepManiaLanServer; 00057 00058 class PacketFunctions 00059 { 00060 public: 00061 unsigned char Data[NETMAXBUFFERSIZE]; //Data 00062 int Position; //Other info (Used for following functions) 00063 int size; //When sending these pacs, Position should 00064 //be used; NOT size. 00065 00066 //Commands used to operate on NetPackets 00067 uint8_t Read1(); 00068 uint16_t Read2(); 00069 uint32_t Read4(); 00070 CString ReadNT(); 00071 00072 void Write1(uint8_t Data); 00073 void Write2(uint16_t Data); 00074 void Write4(uint32_t Data); 00075 void WriteNT(const CString& Data); 00076 00077 void ClearPacket(); 00078 }; 00079 00080 class NetworkSyncManager 00081 { 00082 public: 00083 NetworkSyncManager( LoadingWindow *ld = NULL ); 00084 ~NetworkSyncManager(); 00085 00086 //If "useSMserver" then send score to server 00087 void ReportTiming(float offset, int PlayerNumber); 00088 void ReportScore(int playerID, int step, int score, int combo); 00089 void ReportSongOver(); //Report to server that song is over 00090 void ReportStyle(); //Report to server the style, players, and names 00091 void ReportNSSOnOff(int i); //Report song selection screen on/off 00092 void StartRequest(short position); //Request a start. Block until granted. 00093 CString GetServerName(); 00094 00095 //SMOnline stuff 00096 void SendSMOnline( ); 00097 00098 bool Connect(const CString& addy, unsigned short port); // Connect to SM Server 00099 00100 void PostStartUp(const CString& ServerIP); 00101 00102 void CloseConnection(); 00103 00104 void DisplayStartupStatus(); //Used to note user if connect attempt was sucessful or not. 00105 00106 int m_playerLife[NUM_PLAYERS]; //Life (used for sending to server) 00107 00108 void Update(float fDeltaTime); 00109 00110 bool useSMserver; 00111 bool isSMOnline; 00112 bool isSMOLoggedIn[NUM_PLAYERS]; 00113 00114 vector <int> m_PlayerStatus; 00115 int m_ActivePlayers; 00116 vector <int> m_ActivePlayer; 00117 vector <CString> m_PlayerNames; 00118 00119 //Used for ScreenNetEvaluation 00120 vector<EndOfGame_PlayerData> m_EvalPlayerData; 00121 00122 //Used togeather for 00123 bool ChangedScoreboard(int Column); //If scoreboard changed since this function last called, then true. 00124 CString m_Scoreboard[NUM_NSSB_CATEGORIES]; 00125 00126 //Used for chatting 00127 void SendChat(const CString& message); 00128 CString m_WaitingChat; 00129 00130 //Used for options 00131 void ReportPlayerOptions(); 00132 00133 //Used for song checking/changing 00134 CString m_sMainTitle; 00135 CString m_sArtist; 00136 CString m_sSubTitle; 00137 int m_iSelectMode; 00138 void SelectUserSong(); 00139 00140 CString m_sChatText; 00141 00142 PacketFunctions m_SMOnlinePacket; 00143 00144 bool isLanServer; //Must be public for ScreenNetworkOptions 00145 StepManiaLanServer *LANserver; 00146 00147 private: 00148 #if !defined(WITHOUT_NETWORKING) 00149 00150 void ProcessInput(); 00151 00152 void StartUp(); 00153 00154 float m_lastOffset[2]; //This is used to determine how much 00155 //the last step was off. 00156 00157 int m_playerID; //these are currently unused, but need to stay 00158 int m_step; 00159 int m_score; 00160 int m_combo; 00161 00162 int m_startupStatus; //Used to see if attempt was sucessful or not. 00163 00164 bool m_scoreboardchange[NUM_NSSB_CATEGORIES]; 00165 00166 CString m_ServerName; 00167 00168 EzSockets *NetPlayerClient; 00169 00170 int m_ServerVersion; //ServerVersion 00171 00172 bool Listen(unsigned short port); 00173 00174 PacketFunctions m_packet; 00175 #endif 00176 }; 00177 00178 extern NetworkSyncManager *NSMAN; 00179 00180 #endif 00181 00182 /* 00183 * (c) 2003-2004 Charles Lohr, Joshua Allen 00184 * All rights reserved. 00185 * 00186 * Permission is hereby granted, free of charge, to any person obtaining a 00187 * copy of this software and associated documentation files (the 00188 * "Software"), to deal in the Software without restriction, including 00189 * without limitation the rights to use, copy, modify, merge, publish, 00190 * distribute, and/or sell copies of the Software, and to permit persons to 00191 * whom the Software is furnished to do so, provided that the above 00192 * copyright notice(s) and this permission notice appear in all copies of 00193 * the Software and that both the above copyright notice(s) and this 00194 * permission notice appear in supporting documentation. 00195 * 00196 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00197 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00198 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF 00199 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS 00200 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT 00201 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 00202 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 00203 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00204 * PERFORMANCE OF THIS SOFTWARE. 00205 */

Generated on Thu Jan 27 20:57:25 2005 for StepMania by doxygen 1.3.7