00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef MORTALNETWORKIMPL_H
00010 #define MORTALNETWORKIMPL_H
00011
00012
00013 #include "MortalNetwork.h"
00014 #include "SDL_net.h"
00015 #include <string>
00016 #include <list>
00017
00018
00019 typedef std::list<int> TIntList;
00020 typedef std::list<std::string> TStringList;
00021
00047 class CMortalNetworkImpl: public CMortalNetwork
00048 {
00049 public:
00050 CMortalNetworkImpl();
00051 virtual ~CMortalNetworkImpl();
00052
00053
00054
00055 bool Start( const char* a_pcServerName );
00056 void Stop();
00057 bool IsConnectionAlive();
00058 void Update();
00059 const char* GetLastError();
00060 bool IsMaster();
00061
00062
00063
00064 const char* GetRemoteUsername();
00065 void SendMsg( const char* a_pcMsg );
00066 bool IsMsgAvailable();
00067 const char* GetMsg();
00068
00069
00070
00071 bool IsRemoteFighterAvailable( FighterEnum a_enFighter );
00072 FighterEnum GetRemoteFighter();
00073 bool IsRemoteSideReady();
00074
00075 void SendFighter( FighterEnum a_enFighter );
00076 void SendReady();
00077 void SendGameParams( int a_iGameSpeed, int a_iGameTime, int a_iHitPoints, int a_iBackgroundNumber );
00078 SGameParams GetGameParams();
00079
00080
00081
00082 bool SynchStartRound();
00083 void SendGameData( const char* a_pcGameData );
00084 const char* GetLatestGameData();
00085
00086 void SendKeystroke( int a_iTime, int a_iKey, bool a_bPressed );
00087 bool GetKeystroke( int& a_riOutTime, int& a_riOutKey, bool& a_rbPressed );
00088
00089 void SendGameTick( int a_iGameTick );
00090 int GetGameTick();
00091
00092 void SendHurryup( int a_iHurryUpCode );
00093 int GetHurryup() ;
00094
00095 void SendRoundOver( int a_iWhoWon, bool a_bGameOver );
00096 int GetWhoWon();
00097 bool IsRoundOver();
00098 bool IsGameOver();
00099
00100 protected:
00101 void SendRawData( char a_cID, const void* a_pData, int a_iLength );
00102
00103 void ReceiveMsg( void* a_pData, int a_iLength );
00104 void ReceiveRemoteUserName( void* a_pData, int a_iLength );
00105 void ReceiveGameData( void* a_pData, int a_iLength );
00106 void ReceiveKeystroke( void* a_pData, int a_iLength );
00107 void ReceiveFighter( void* a_pData, int a_iLength );
00108 void ReceiveReady( void* a_pData, int a_iLength );
00109 void ReceiveRoundOver( void* a_pData, int a_iLength );
00110 void ReceiveGameTick( void* a_pData, int a_iLength );
00111 void ReceiveHurryup( void* a_pData, int a_iLength );
00112 void ReceiveRemoteFighterAvailable( void* a_pData, int a_iLength );
00113 void ReceiveRemoteFighterQuery( void* a_pData, int a_iLength );
00114 void ReceiveGameParams( void* a_pData, int a_iLength );
00115
00116 protected:
00117
00118 enum TNetworkState
00119 {
00120 NS_DISCONNECTED,
00121 NS_CHARACTER_SELECTION,
00122 NS_IN_GAME,
00123 };
00124
00125
00126
00127 bool m_bNetworkAvailable;
00128 TNetworkState m_enState;
00129 bool m_bServer;
00130 bool m_bMaster;
00131 TCPsocket m_poSocket;
00132 SDLNet_SocketSet m_poSocketSet;
00133
00134 char m_acIncomingBuffer[2048];
00135 int m_iIncomingBufferSize;
00136
00137 std::string m_sLastError;
00138 TStringList m_asMsgs;
00139
00140
00141
00142 std::string m_sRemoteUserName;
00143 TIntList m_aiAvailableRemoteFighters;
00144 FighterEnum m_enRemoteFighter;
00145 bool m_bRemoteReady;
00146 SGameParams m_oGameParams;
00147
00148 std::string m_sLatestGameData;
00149 TIntList m_aiKeyTimes;
00150 TIntList m_aiKeystrokes;
00151 TIntList m_abKeystrokes;
00152
00153 bool m_bRoundOver;
00154 int m_iWhoWon;
00155 bool m_bGameOver;
00156 int m_iGameTick;
00157 int m_iHurryupCode;
00158
00159
00160
00161 bool m_bSynchQueryResponse;
00162 };
00163
00164
00165 #endif // MORTALNETWORKIMPL_H
00166