Files
itgmania212121/src/NetworkSyncManager.h
T

234 lines
5.6 KiB
C++
Raw Normal View History

2004-06-08 01:24:17 +00:00
/* NetworkSyncManager - Uses ezsockets for primitive song syncing and score reporting. */
#ifndef NetworkSyncManager_H
#define NetworkSyncManager_H
2004-03-30 07:43:12 +00:00
#include "PlayerNumber.h"
2004-09-01 17:16:01 +00:00
#include "Difficulty.h"
#include <queue>
2004-08-28 05:30:23 +00:00
2004-08-18 01:29:51 +00:00
class LoadingWindow;
const int NETPROTOCOLVERSION=3;
2004-06-30 07:16:44 +00:00
const int NETMAXBUFFERSIZE=1020; //1024 - 4 bytes for EzSockets
const int NETNUMTAPSCORES=8;
enum NSCommand
{
NSCPing = 0,
NSCPingR, //1
NSCHello, //2
NSCGSR, //3
NSCGON, //4
NSCGSU, //5
NSCSU, //6
NSCCM, //7
NSCRSG, //8
NSCUUL, //9
NSCSMS, //10
NSCUPOpts, //11
NSCSMOnline, //12
NSCFormatted, //13
2006-04-19 05:29:47 +00:00
NSCAttack, //14
NUM_NS_COMMANDS
};
enum SMOStepType
{
SMOST_UNUSED = 0,
2007-08-19 20:49:21 +00:00
SMOST_HITMINE,
SMOST_AVOIDMINE,
2007-08-19 21:04:40 +00:00
SMOST_MISS,
SMOST_W5,
SMOST_W4,
SMOST_W3,
SMOST_W2,
SMOST_W1,
SMOST_LETGO,
SMOST_HELD
};
const NSCommand NSServerOffset = (NSCommand)128;
struct EndOfGame_PlayerData
{
int name;
int score;
int grade;
2004-09-01 17:16:01 +00:00
Difficulty difficulty;
int tapScores[NETNUMTAPSCORES]; //This will be a const soon enough
2006-01-22 01:00:06 +00:00
RString playerOptions;
};
2004-06-30 07:16:44 +00:00
2004-08-13 08:24:11 +00:00
enum NSScoreBoardColumn
{
NSSB_NAMES=0,
NSSB_COMBO,
NSSB_GRADE,
2006-09-27 04:38:26 +00:00
NUM_NSScoreBoardColumn,
NSScoreBoardColumn_Invalid
2004-08-13 08:24:11 +00:00
};
2006-10-07 08:56:58 +00:00
#define FOREACH_NSScoreBoardColumn( sc ) FOREACH_ENUM( NSScoreBoardColumn, sc )
2004-08-13 08:24:11 +00:00
struct NetServerInfo
{
2006-01-22 01:00:06 +00:00
RString Name;
RString Address;
};
2004-03-17 06:05:52 +00:00
class EzSockets;
2004-08-28 05:30:23 +00:00
class StepManiaLanServer;
class PacketFunctions
{
public:
unsigned char Data[NETMAXBUFFERSIZE]; //Data
int Position; //Other info (Used for following functions)
int size; //When sending these pacs, Position should
//be used; NOT size.
//Commands used to operate on NetPackets
uint8_t Read1();
uint16_t Read2();
uint32_t Read4();
2006-01-22 01:00:06 +00:00
RString ReadNT();
void Write1( uint8_t Data );
void Write2( uint16_t Data );
void Write4( uint32_t Data );
void WriteNT( const RString& Data );
void ClearPacket();
};
class NetworkSyncManager
{
public:
2004-08-18 01:29:51 +00:00
NetworkSyncManager( LoadingWindow *ld = NULL );
~NetworkSyncManager();
2004-03-17 13:31:42 +00:00
//If "useSMserver" then send score to server
void ReportScore( int playerID, int step, int score, int combo, float offset );
void ReportSongOver(); //Report to server that song is over
void ReportStyle(); //Report to server the style, players, and names
void ReportNSSOnOff( int i ); //Report song selection screen on/off
void StartRequest( short position ); //Request a start. Block until granted.
2006-01-22 01:00:06 +00:00
RString GetServerName();
//SMOnline stuff
void SendSMOnline( );
bool Connect( const RString& addy, unsigned short port ); // Connect to SM Server
void PostStartUp( const RString& ServerIP );
void CloseConnection();
2005-04-02 16:29:29 +00:00
void DisplayStartupStatus(); //Used to note user if connect attempt was successful or not.
int m_playerLife[NUM_PLAYERS]; //Life (used for sending to server)
void Update( float fDeltaTime );
2004-08-13 08:24:11 +00:00
bool useSMserver;
bool isSMOnline;
bool isSMOLoggedIn[NUM_PLAYERS];
2004-08-13 08:24:11 +00:00
vector <int> m_PlayerStatus;
int m_ActivePlayers;
vector <int> m_ActivePlayer;
2006-01-22 01:00:06 +00:00
vector <RString> m_PlayerNames;
2004-08-13 08:24:11 +00:00
//Used for ScreenNetEvaluation
vector<EndOfGame_PlayerData> m_EvalPlayerData;
2004-08-13 08:24:11 +00:00
//Used togeather for
bool ChangedScoreboard(int Column); //If scoreboard changed since this function last called, then true.
2006-09-27 04:38:26 +00:00
RString m_Scoreboard[NUM_NSScoreBoardColumn];
//Used for chatting
2006-01-22 01:00:06 +00:00
void SendChat(const RString& message);
RString m_WaitingChat;
2004-08-28 03:37:52 +00:00
2004-09-06 03:25:26 +00:00
//Used for options
void ReportPlayerOptions();
2004-08-28 03:37:52 +00:00
//Used for song checking/changing
2006-01-22 01:00:06 +00:00
RString m_sMainTitle;
RString m_sArtist;
RString m_sSubTitle;
2004-08-28 03:37:52 +00:00
int m_iSelectMode;
void SelectUserSong();
RString m_sChatText;
PacketFunctions m_SMOnlinePacket;
StepManiaLanServer *LANserver;
2005-05-08 08:49:01 +00:00
int GetSMOnlineSalt();
2006-01-22 01:00:06 +00:00
RString MD5Hex( const RString &sInput );
void GetListOfLANServers( vector<NetServerInfo>& AllServers );
2004-03-17 13:31:42 +00:00
private:
#if !defined(WITHOUT_NETWORKING)
2004-06-30 07:16:44 +00:00
void ProcessInput();
SMOStepType TranslateStepType(int score);
void StartUp();
int m_playerID; //these are currently unused, but need to stay
int m_step;
int m_score;
int m_combo;
2005-04-02 16:29:29 +00:00
int m_startupStatus; //Used to see if attempt was successful or not.
int m_iSalt;
2006-09-27 04:38:26 +00:00
bool m_scoreboardchange[NUM_NSScoreBoardColumn];
2004-06-30 07:16:44 +00:00
2006-01-22 01:00:06 +00:00
RString m_ServerName;
EzSockets *NetPlayerClient;
EzSockets *BroadcastReception;
vector<NetServerInfo> m_vAllLANServers;
int m_ServerVersion; //ServerVersion
bool Listen( unsigned short port );
PacketFunctions m_packet;
2004-06-15 02:21:16 +00:00
#endif
};
2004-03-17 06:05:52 +00:00
extern NetworkSyncManager *NSMAN;
#endif
2004-06-08 01:24:17 +00:00
/*
* (c) 2003-2004 Charles Lohr, Joshua Allen
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/