Broekn
This commit is contained in:
parent
830b448690
commit
5b4758d2ae
|
@ -81,7 +81,7 @@ void NetLoadState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientE
|
||||||
|
|
||||||
if( ID == protocol_Lobby_CreateGame && !this->privData->loading )
|
if( ID == protocol_Lobby_CreateGame && !this->privData->loading )
|
||||||
{
|
{
|
||||||
this->LoadGame( Protocol_LobbyCreateGame(e.args.data.protocol).modelName );
|
this->LoadGame( Protocol_LobbyCreateGame(e.args.data.protocol).mapName );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,61 +41,41 @@ namespace GameLogic
|
||||||
|
|
||||||
struct Protocol_LobbyCreateGame :public Oyster::Network::CustomProtocolObject
|
struct Protocol_LobbyCreateGame :public Oyster::Network::CustomProtocolObject
|
||||||
{
|
{
|
||||||
short clientID; // The unuiqe id reprsenting a specific client
|
char majorVersion;
|
||||||
std::string modelName;
|
char minorVersion;
|
||||||
float worldMatrix[16];
|
std::string mapName;
|
||||||
|
|
||||||
Protocol_LobbyCreateGame()
|
Protocol_LobbyCreateGame()
|
||||||
{
|
{
|
||||||
int c = 0;
|
this->protocol[0].value = protocol_Lobby_CreateGame;
|
||||||
this->protocol[c].value = protocol_Lobby_CreateGame;
|
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
|
||||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
|
this->protocol[1].type = Oyster::Network::NetAttributeType_Char;
|
||||||
|
this->protocol[2].type = Oyster::Network::NetAttributeType_Char;
|
||||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
|
this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray;
|
||||||
for (int i = 0; i <= 16; i++)
|
|
||||||
{
|
|
||||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_Float;
|
|
||||||
}
|
}
|
||||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_CharArray;
|
Protocol_LobbyCreateGame(char majorVersion, char minorVersion, std::string name)
|
||||||
}
|
|
||||||
Protocol_LobbyCreateGame(short _clientID, std::string name, float world[16])
|
|
||||||
{
|
{
|
||||||
int c = 0;
|
this->protocol[0].value = protocol_Lobby_CreateGame;
|
||||||
this->protocol[c].value = protocol_Lobby_CreateGame;
|
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
|
||||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
|
this->protocol[1].type = Oyster::Network::NetAttributeType_Char;
|
||||||
|
this->protocol[2].type = Oyster::Network::NetAttributeType_Char;
|
||||||
|
this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray;
|
||||||
|
|
||||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
|
this->majorVersion = majorVersion;
|
||||||
for (int i = 0; i <= 16; i++)
|
this->minorVersion = minorVersion;
|
||||||
{
|
this->mapName = name;
|
||||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_Float;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->protocol[c++].type = Oyster::Network::NetAttributeType_CharArray;
|
|
||||||
|
|
||||||
clientID = _clientID;
|
|
||||||
modelName = name;
|
|
||||||
memcpy(&worldMatrix[0], &world[0], sizeof(float) * 16);
|
|
||||||
}
|
}
|
||||||
Protocol_LobbyCreateGame(Oyster::Network::CustomNetProtocol o)
|
Protocol_LobbyCreateGame(Oyster::Network::CustomNetProtocol o)
|
||||||
{
|
{
|
||||||
int c = 1;
|
this->majorVersion = o[1].value.netChar;
|
||||||
clientID = o[c++].value.netInt;
|
this->minorVersion = o[2].value.netChar;
|
||||||
for (int i = 0; i <= 16; i++)
|
this->mapName.assign(o[3].value.netCharPtr);
|
||||||
{
|
|
||||||
this->worldMatrix[i] = o[c++].value.netFloat;
|
|
||||||
}
|
|
||||||
modelName.assign(o[c++].value.netCharPtr);
|
|
||||||
}
|
}
|
||||||
Oyster::Network::CustomNetProtocol GetProtocol() override
|
Oyster::Network::CustomNetProtocol GetProtocol() override
|
||||||
{
|
{
|
||||||
int c = 1;
|
protocol[1].value = this->majorVersion;
|
||||||
protocol[c++].value = clientID;
|
protocol[2].value = this->minorVersion;
|
||||||
|
protocol.Set(3, this->mapName);
|
||||||
for (int i = 0; i <= 16; i++)
|
|
||||||
{
|
|
||||||
this->protocol[c++].value = this->worldMatrix[i];
|
|
||||||
}
|
|
||||||
protocol.Set(c++, this->modelName);
|
|
||||||
return protocol;
|
return protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,19 +25,31 @@ namespace DanBias
|
||||||
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> GetClient();
|
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> GetClient();
|
||||||
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> ReleaseClient();
|
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> ReleaseClient();
|
||||||
|
|
||||||
float GetSinceLastResponse() const;
|
inline bool operator==(const GameLogic::IPlayerData* c) { return (this->player) ? (c->GetID() == this->player->GetID()) : false ; }
|
||||||
bool IsReady() const;
|
inline bool operator==(const Oyster::Network::NetworkClient* c) { return (c->GetID() == this->GetID()); }
|
||||||
bool Equals(const Oyster::Network::NetworkClient* c);
|
|
||||||
|
|
||||||
|
inline float GetSinceLastResponse() const { return this->secondsSinceLastResponse; }
|
||||||
|
inline std::wstring GetAlias() const { return this->alias; }
|
||||||
|
inline std::wstring GetCharacter() const { return this->character; }
|
||||||
|
inline bool IsReady() const { return this->isReady; }
|
||||||
|
inline GameLogic::IPlayerData* GetPlayer() const { return this->player; }
|
||||||
|
|
||||||
|
|
||||||
|
void SetPlayer(GameLogic::IPlayerData* player);
|
||||||
void SetReadyState(bool isReady);
|
void SetReadyState(bool isReady);
|
||||||
|
void SetAlias(std::wstring alias);
|
||||||
|
void SetCharacter(std::wstring character);
|
||||||
void SetSinceLastResponse(float seconds);
|
void SetSinceLastResponse(float seconds);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GameLogic::IPlayerData* player;
|
GameLogic::IPlayerData* player;
|
||||||
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client;
|
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client;
|
||||||
|
|
||||||
bool isReady;
|
bool isReady;
|
||||||
float secondsSinceLastResponse;
|
float secondsSinceLastResponse;
|
||||||
};
|
|
||||||
|
|
||||||
|
std::wstring alias;
|
||||||
|
std::wstring character;
|
||||||
|
};
|
||||||
}//End namespace DanBias
|
}//End namespace DanBias
|
||||||
#endif // !DANBIASSERVER_CLIENT_OBJECT_H
|
#endif // !DANBIASSERVER_CLIENT_OBJECT_H
|
||||||
|
|
|
@ -38,10 +38,8 @@ namespace DanBias
|
||||||
|
|
||||||
void GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Status:
|
void GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Status:
|
||||||
void GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Text:
|
void GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Text:
|
||||||
//void LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Create:
|
|
||||||
void LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Start:
|
void LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Start:
|
||||||
//void LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Join:
|
void LobbyJoin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login:
|
||||||
void LobbyLogin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login:
|
|
||||||
void LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Refresh:
|
void LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Refresh:
|
||||||
void LobbyGameData(GameLogic::Protocol_LobbyGameData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_GameData:
|
void LobbyGameData(GameLogic::Protocol_LobbyGameData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_GameData:
|
||||||
void LobbyMainData(GameLogic::Protocol_LobbyClientData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_MainData:
|
void LobbyMainData(GameLogic::Protocol_LobbyClientData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_MainData:
|
||||||
|
@ -53,8 +51,9 @@ namespace DanBias
|
||||||
void ClientConnectedEvent(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client) override;
|
void ClientConnectedEvent(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Utility::WinTimer timer;
|
//Utility::WinTimer timer;
|
||||||
float refreshFrequency;
|
//float refreshFrequency;
|
||||||
|
|
||||||
Utility::DynamicMemory::LinkedList<Oyster::Network::NetworkClient*> readyList;
|
Utility::DynamicMemory::LinkedList<Oyster::Network::NetworkClient*> readyList;
|
||||||
GameSession gameSession;
|
GameSession gameSession;
|
||||||
LobbyLevelData description;
|
LobbyLevelData description;
|
||||||
|
|
|
@ -31,10 +31,10 @@ namespace DanBias
|
||||||
*/
|
*/
|
||||||
struct GameDescription
|
struct GameDescription
|
||||||
{
|
{
|
||||||
int maxClients;
|
unsigned int maxClients;
|
||||||
int mapNumber;
|
std::string mapName;
|
||||||
int gameMode;
|
std::string gameMode;
|
||||||
int gameTime;
|
int gameTimeMinutes;
|
||||||
Oyster::Network::NetworkSession* owner;
|
Oyster::Network::NetworkSession* owner;
|
||||||
Utility::DynamicMemory::DynamicArray<Oyster::Network::NetClient> clients;
|
Utility::DynamicMemory::DynamicArray<Oyster::Network::NetClient> clients;
|
||||||
};
|
};
|
||||||
|
@ -61,14 +61,14 @@ namespace DanBias
|
||||||
|
|
||||||
//Private member functions
|
//Private member functions
|
||||||
private:
|
private:
|
||||||
// TODO: find out what this method does..
|
// Client event callback function
|
||||||
void ClientEventCallback(Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e) override;
|
void ClientEventCallback(Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e) override;
|
||||||
|
|
||||||
//Sends a client to the owner, if obj is NULL then all clients is sent
|
//Sends a client to the owner, if param is NULL then all clients is sent
|
||||||
void SendToOwner(DanBias::GameClient* obj);
|
void SendToOwner(DanBias::GameClient* obj);
|
||||||
|
|
||||||
//Derived from IThreadObject
|
//Derived from IThreadObject
|
||||||
void ThreadEntry() override;
|
void ThreadEntry( ) override;
|
||||||
bool DoWork ( ) override;
|
bool DoWork ( ) override;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,51 +12,26 @@ using namespace DanBias;
|
||||||
using namespace GameLogic;
|
using namespace GameLogic;
|
||||||
|
|
||||||
|
|
||||||
GameClient::GameClient(SmartPointer<NetworkClient> client, GameLogic::IPlayerData* player)
|
GameClient::GameClient()
|
||||||
{
|
{
|
||||||
this->client = client;
|
this->player = 0;
|
||||||
this->player = player;
|
|
||||||
isReady = false;
|
isReady = false;
|
||||||
|
this->character = L"Unknown";
|
||||||
|
this->alias = L"Unknown";
|
||||||
|
this->secondsSinceLastResponse = 0.0f;
|
||||||
}
|
}
|
||||||
GameClient::~GameClient()
|
GameClient::~GameClient()
|
||||||
{
|
{
|
||||||
this->client->Disconnect();
|
|
||||||
this->player = 0;
|
this->player = 0;
|
||||||
isReady = false;
|
this->isReady = false;
|
||||||
|
this->character = L"Unknown";
|
||||||
|
this->alias = L"Unknown";
|
||||||
|
this->secondsSinceLastResponse = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLogic::IPlayerData* GameClient::GetPlayer()
|
void GameClient::SetPlayer(GameLogic::IPlayerData* player)
|
||||||
{
|
{
|
||||||
return this->player;
|
this->player = player;
|
||||||
}
|
|
||||||
GameLogic::IPlayerData* GameClient::ReleasePlayer()
|
|
||||||
{
|
|
||||||
GameLogic::IPlayerData *temp = this->player;
|
|
||||||
this->player = 0;
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
SmartPointer<Oyster::Network::NetworkClient> GameClient::GetClient()
|
|
||||||
{
|
|
||||||
return this->client;
|
|
||||||
}
|
|
||||||
SmartPointer<Oyster::Network::NetworkClient> GameClient::ReleaseClient()
|
|
||||||
{
|
|
||||||
SmartPointer<Oyster::Network::NetworkClient> temp = this->client;
|
|
||||||
this->client = 0;
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
float GameClient::GetSinceLastResponse() const
|
|
||||||
{
|
|
||||||
return this->secondsSinceLastResponse;
|
|
||||||
}
|
|
||||||
bool GameClient::IsReady() const
|
|
||||||
{
|
|
||||||
return this->isReady;
|
|
||||||
}
|
|
||||||
bool GameClient::Equals(const NetworkClient* c)
|
|
||||||
{
|
|
||||||
return (c->GetID() == this->client->GetID());
|
|
||||||
}
|
}
|
||||||
void GameClient::SetReadyState(bool r)
|
void GameClient::SetReadyState(bool r)
|
||||||
{
|
{
|
||||||
|
@ -66,5 +41,13 @@ void GameClient::SetSinceLastResponse(float s)
|
||||||
{
|
{
|
||||||
this->secondsSinceLastResponse = s;
|
this->secondsSinceLastResponse = s;
|
||||||
}
|
}
|
||||||
|
void GameClient::SetAlias(std::wstring alias)
|
||||||
|
{
|
||||||
|
this->alias = alias;
|
||||||
|
}
|
||||||
|
void GameClient::SetCharacter(std::wstring character)
|
||||||
|
{
|
||||||
|
this->character = character;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -56,13 +56,13 @@ bool GameLobby::StartGameSession( )
|
||||||
GameSession::GameDescription desc;
|
GameSession::GameDescription desc;
|
||||||
desc.maxClients = this->description.maxClients;
|
desc.maxClients = this->description.maxClients;
|
||||||
desc.gameMode = this->description.gameMode;
|
desc.gameMode = this->description.gameMode;
|
||||||
desc.gameTime = this->description.gameTime;
|
desc.gameTimeMinutes = this->description.gameTime;
|
||||||
desc.mapNumber = this->description.mapNumber;
|
//desc.mapName = this->description.mapNumber;
|
||||||
desc.owner = this;
|
desc.owner = this;
|
||||||
desc.clients = this->clients;
|
desc.clients = this->clients;
|
||||||
|
|
||||||
if(desc.gameTime == 0.0f)
|
if(desc.gameTimeMinutes == 0)
|
||||||
desc.gameTime = (int)(60.0f * 10.0f); //note: should be fetched from somewhere.
|
desc.gameTimeMinutes = 10; //note: should be fetched from somewhere.
|
||||||
|
|
||||||
if(desc.maxClients == 0)
|
if(desc.maxClients == 0)
|
||||||
desc.maxClients = 10; //note: should be fetched somewhere else..
|
desc.maxClients = 10; //note: should be fetched somewhere else..
|
||||||
|
|
|
@ -16,13 +16,9 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie
|
||||||
break;
|
break;
|
||||||
case protocol_General_Text: this->GeneralText (Protocol_General_Text (p), c);
|
case protocol_General_Text: this->GeneralText (Protocol_General_Text (p), c);
|
||||||
break;
|
break;
|
||||||
//case protocol_Lobby_Create: this->LobbyCreateGame (Protocol_LobbyCreateGame (p), c);
|
|
||||||
//break;
|
|
||||||
case protocol_Lobby_StartGame: this->LobbyStartGame (Protocol_LobbyStartGame (p), c);
|
case protocol_Lobby_StartGame: this->LobbyStartGame (Protocol_LobbyStartGame (p), c);
|
||||||
break;
|
break;
|
||||||
//case protocol_Lobby_Join: this->LobbyJoin (Protocol_LobbyJoin (p), c);
|
case protocol_Lobby_JoinGame: this->LobbyJoin (Protocol_LobbyJoinGame (p), c);
|
||||||
//break;
|
|
||||||
case protocol_Lobby_Login: this->LobbyLogin (Protocol_LobbyJoinGame (p), c);
|
|
||||||
break;
|
break;
|
||||||
case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c);
|
case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c);
|
||||||
break;
|
break;
|
||||||
|
@ -32,7 +28,7 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie
|
||||||
break;
|
break;
|
||||||
case protocol_Lobby_ClientReadyState: this->LobbyReady (Protocol_LobbyClientReadyState (p), c);
|
case protocol_Lobby_ClientReadyState: this->LobbyReady (Protocol_LobbyClientReadyState (p), c);
|
||||||
break;
|
break;
|
||||||
case protocol_Lobby_QuerryGameType: this->LobbyReady (Protocol_LobbyClientReadyState (p), c);
|
case protocol_Lobby_QuerryGameType: this->LobbyQuerryGameData (Protocol_QuerryGameType (), c);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,37 +55,40 @@ void GameLobby::GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Net
|
||||||
}
|
}
|
||||||
void GameLobby::GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c)
|
void GameLobby::GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c)
|
||||||
{
|
{
|
||||||
|
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
||||||
|
{
|
||||||
|
if(this->clients[i])
|
||||||
|
{
|
||||||
|
this->clients[i]->Send(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
printf(p.text.c_str());
|
printf(p.text.c_str());
|
||||||
}
|
}
|
||||||
//void GameLobby::LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c)
|
|
||||||
//{
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
void GameLobby::LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c)
|
void GameLobby::LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c)
|
||||||
{
|
{
|
||||||
if(this->sessionOwner->GetClient()->GetID() == c->GetID())
|
if(this->sessionOwner->GetClient()->GetID() == c->GetID())
|
||||||
{
|
{
|
||||||
|
//Send countdown timer before lobby shuts down
|
||||||
|
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
||||||
|
{
|
||||||
|
this->clients[i]->Send(Protocol_LobbyStartGame(3.0f));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Someone else tried to start the server..
|
//Someone else tried to start the server..
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//void GameLobby::LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c)
|
void GameLobby::LobbyJoin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c)
|
||||||
//{
|
|
||||||
// //for (unsigned int i = 0; i < this->gameLobby.Size(); i++)
|
|
||||||
// //{
|
|
||||||
// // if (this->gameLobby[i]->GetID() == p.value)
|
|
||||||
// // {
|
|
||||||
// // this->gameLobby[i]->Attach(Detach(c));
|
|
||||||
// // return;
|
|
||||||
// // }
|
|
||||||
// //}
|
|
||||||
//}
|
|
||||||
void GameLobby::LobbyLogin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c)
|
|
||||||
{
|
{
|
||||||
|
//for (unsigned int i = 0; i < this->gameLobby.Size(); i++)
|
||||||
|
//{
|
||||||
|
// if (this->gameLobby[i]->GetID() == p.value)
|
||||||
|
// {
|
||||||
|
// this->gameLobby[i]->Attach(Detach(c));
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
void GameLobby::LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c)
|
void GameLobby::LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c)
|
||||||
{
|
{
|
||||||
|
@ -112,6 +111,7 @@ void GameLobby::LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster:
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->readyList.Remove(c);
|
this->readyList.Remove(c);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void GameLobby::LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c)
|
void GameLobby::LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c)
|
||||||
|
|
|
@ -19,11 +19,8 @@ using namespace Oyster;
|
||||||
using namespace Oyster::Network;
|
using namespace Oyster::Network;
|
||||||
using namespace Oyster::Thread;
|
using namespace Oyster::Thread;
|
||||||
using namespace GameLogic;
|
using namespace GameLogic;
|
||||||
|
using namespace DanBias;
|
||||||
|
|
||||||
namespace DanBias
|
|
||||||
{
|
|
||||||
Utility::WinTimer testTimer;
|
|
||||||
int testID = -1;
|
|
||||||
|
|
||||||
bool GameSession::DoWork( )
|
bool GameSession::DoWork( )
|
||||||
{
|
{
|
||||||
|
@ -246,7 +243,6 @@ namespace DanBias
|
||||||
printf("Message recieved from (%i):\t %s\n", c->GetClient()->GetID(), p.text.c_str());
|
printf("Message recieved from (%i):\t %s\n", c->GetClient()->GetID(), p.text.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
}//End namespace DanBias
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,14 +24,13 @@ using namespace Oyster;
|
||||||
using namespace Oyster::Network;
|
using namespace Oyster::Network;
|
||||||
using namespace Oyster::Thread;
|
using namespace Oyster::Thread;
|
||||||
using namespace GameLogic;
|
using namespace GameLogic;
|
||||||
|
using namespace DanBias;
|
||||||
|
|
||||||
namespace DanBias
|
GameSession* GameSession::gameSession = nullptr;
|
||||||
{
|
|
||||||
GameSession* GameSession::gameSession = nullptr;
|
|
||||||
|
|
||||||
GameSession::GameSession()
|
GameSession::GameSession()
|
||||||
:gameInstance(GameAPI::Instance())
|
:gameInstance(GameAPI::Instance())
|
||||||
{
|
{
|
||||||
this->owner = 0;
|
this->owner = 0;
|
||||||
this->isCreated = false;
|
this->isCreated = false;
|
||||||
this->isRunning = false;
|
this->isRunning = false;
|
||||||
|
@ -42,39 +41,39 @@ namespace DanBias
|
||||||
this->logicTimer.reset();
|
this->logicTimer.reset();
|
||||||
|
|
||||||
memset(&this->description, 0, sizeof(GameDescription));
|
memset(&this->description, 0, sizeof(GameDescription));
|
||||||
}
|
}
|
||||||
|
|
||||||
GameSession::~GameSession()
|
GameSession::~GameSession()
|
||||||
{
|
{
|
||||||
this->worker.Terminate();
|
this->worker.Terminate();
|
||||||
this->clients.Clear();
|
this->clients.Clear();
|
||||||
this->gameInstance;
|
this->gameInstance;
|
||||||
this->owner = 0;
|
this->owner = 0;
|
||||||
this->isCreated = false;
|
this->isCreated = false;
|
||||||
this->isRunning = false;
|
this->isRunning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameSession::Create(GameDescription& desc)
|
bool GameSession::Create(GameDescription& desc)
|
||||||
{
|
{
|
||||||
this->description = desc;
|
this->description = desc;
|
||||||
/* Do some error checking */
|
/* Do some error checking */
|
||||||
if(desc.clients.Size() == 0) return false;
|
if(desc.clients.Size() == 0) return false;
|
||||||
if(!desc.owner) return false;
|
if(!desc.owner) return false;
|
||||||
if(this->isCreated) return false;
|
if(this->isCreated) return false;
|
||||||
|
|
||||||
/* standard initialization of some data */
|
/* standard initialization of some data */
|
||||||
NetworkSession::clients = desc.clients;
|
NetworkSession::clients = desc.clients;
|
||||||
NetworkSession::clients.Resize((unsigned int)desc.maxClients);
|
NetworkSession::clients.Resize((unsigned int)desc.maxClients);
|
||||||
this->clients.Resize((unsigned int)desc.maxClients);
|
this->clients.Resize((unsigned int)desc.maxClients);
|
||||||
this->owner = desc.owner;
|
this->owner = desc.owner;
|
||||||
|
|
||||||
/* Initiate the game instance */
|
/* Initiate the game instance */
|
||||||
if(!this->gameInstance.Initiate())
|
if(!this->gameInstance.Initiate())
|
||||||
{
|
{
|
||||||
printf("Failed to initiate the game instance\n");
|
printf("Failed to initiate the game instance\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create the players in the game instance */
|
/* Create the players in the game instance */
|
||||||
GameLogic::IPlayerData* p = 0;
|
GameLogic::IPlayerData* p = 0;
|
||||||
for (unsigned int i = 0; i < desc.clients.Size(); i++)
|
for (unsigned int i = 0; i < desc.clients.Size(); i++)
|
||||||
{
|
{
|
||||||
|
@ -92,14 +91,14 @@ namespace DanBias
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create the game level */
|
/* Create the game level */
|
||||||
if(!(this->levelData = this->gameInstance.CreateLevel()))
|
if(!(this->levelData = this->gameInstance.CreateLevel()))
|
||||||
{
|
{
|
||||||
printf("Level not created!");
|
printf("Level not created!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set some game instance data options */
|
/* Set some game instance data options */
|
||||||
this->gameInstance.SetSubscription(GameSession::ObjectMove);
|
this->gameInstance.SetSubscription(GameSession::ObjectMove);
|
||||||
this->gameInstance.SetSubscription(GameSession::ObjectDisabled);
|
this->gameInstance.SetSubscription(GameSession::ObjectDisabled);
|
||||||
this->gameInstance.SetFPS(60);
|
this->gameInstance.SetFPS(60);
|
||||||
|
@ -113,10 +112,10 @@ namespace DanBias
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return this->isCreated;
|
return this->isCreated;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameSession::Run()
|
void GameSession::Run()
|
||||||
{
|
{
|
||||||
if(this->isRunning) return;
|
if(this->isRunning) return;
|
||||||
|
|
||||||
if(this->clients.Size() > 0)
|
if(this->clients.Size() > 0)
|
||||||
|
@ -125,30 +124,27 @@ namespace DanBias
|
||||||
this->worker.SetPriority(OYSTER_THREAD_PRIORITY_1);
|
this->worker.SetPriority(OYSTER_THREAD_PRIORITY_1);
|
||||||
this->isRunning = true;
|
this->isRunning = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameSession::ThreadEntry( )
|
void GameSession::ThreadEntry( )
|
||||||
{
|
{
|
||||||
//List with clients that we are waiting on..
|
//List with clients that we are waiting on..
|
||||||
DynamicArray<SmartPointer<GameClient>> readyList;// = this->clients;
|
DynamicArray<SmartPointer<GameClient>> readyList;// = this->clients;
|
||||||
|
|
||||||
//First we need to clean invalid clients, if any, and tell them to start loading game data
|
//First we need to clean invalid clients, if any, and tell them to start loading game data
|
||||||
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
||||||
{
|
{
|
||||||
if(this->clients[i])
|
if(this->clients[i])
|
||||||
{
|
|
||||||
if(this->clients[i]->IsReady())
|
|
||||||
{
|
{
|
||||||
readyList.Push(this->clients[i]);
|
readyList.Push(this->clients[i]);
|
||||||
Protocol_LobbyCreateGame p(readyList[i]->GetPlayer()->GetID(), "char_white.dan", readyList[i]->GetPlayer()->GetOrientation());
|
Protocol_LobbyCreateGame p((char)1, (char)0, this->description.mapName);
|
||||||
readyList[readyList.Size() - 1]->GetClient()->Send(p);
|
readyList[readyList.Size() - 1]->GetClient()->Send(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int readyCounter = readyList.Size();
|
unsigned int readyCounter = readyList.Size();
|
||||||
|
|
||||||
//Sync with clients
|
//Sync with clients
|
||||||
while (readyCounter != 0)
|
while (readyCounter != 0)
|
||||||
{
|
{
|
||||||
this->ProcessClients();
|
this->ProcessClients();
|
||||||
|
@ -161,11 +157,10 @@ namespace DanBias
|
||||||
{
|
{
|
||||||
if((this->clients[k] && readyList[i]) && readyList[i]->GetClient()->GetID() != this->clients[k]->GetClient()->GetID())
|
if((this->clients[k] && readyList[i]) && readyList[i]->GetClient()->GetID() != this->clients[k]->GetClient()->GetID())
|
||||||
{
|
{
|
||||||
//Protocol_ObjectCreatePlayer
|
IPlayerData* pl = this->clients[k]->GetPlayer();
|
||||||
Protocol_ObjectCreate p( this->clients[k]->GetPlayer()->GetPosition(),
|
Protocol_ObjectCreatePlayer p( pl->GetPosition(), pl->GetRotation(), pl->GetScale(),
|
||||||
this->clients[k]->GetPlayer()->GetRotation(),
|
pl->GetID(), true, this->clients[k]->GetPlayer()->GetTeamID(),
|
||||||
this->clients[k]->GetPlayer()->GetScale(),
|
/*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan");
|
||||||
this->clients[k]->GetPlayer()->GetID(), "char_white.dan"); //The model name will be custom later..
|
|
||||||
readyList[i]->GetClient()->Send(p);
|
readyList[i]->GetClient()->Send(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,6 +172,8 @@ namespace DanBias
|
||||||
Sleep(5); //TODO: This might not be needed here.
|
Sleep(5); //TODO: This might not be needed here.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Sync with clients before starting countdown
|
||||||
|
|
||||||
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
||||||
{
|
{
|
||||||
if(this->clients[i])
|
if(this->clients[i])
|
||||||
|
@ -184,57 +181,86 @@ namespace DanBias
|
||||||
this->clients[i]->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(5));
|
this->clients[i]->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameSession::Attach(Utility::DynamicMemory::SmartPointer<NetworkClient> client)
|
bool GameSession::Attach(Utility::DynamicMemory::SmartPointer<NetworkClient> networkClient)
|
||||||
{
|
{
|
||||||
if(!this->isCreated) return false;
|
if(!this->isCreated) return false;
|
||||||
if(this->GetClientCount() == this->clients.Capacity()) return false;
|
if(this->GetClientCount() == this->clients.Capacity()) return false;
|
||||||
|
|
||||||
client->SetOwner(this);
|
networkClient->SetOwner(this);
|
||||||
|
|
||||||
IPlayerData* player = this->gameInstance.CreatePlayer();
|
IPlayerData* playerData = this->gameInstance.CreatePlayer();
|
||||||
if(!player) return false;
|
if(!playerData) return false;
|
||||||
|
|
||||||
SmartPointer<GameClient> obj = new GameClient(client, player);
|
SmartPointer<GameClient> gameClient = new GameClient(networkClient, playerData);
|
||||||
|
NetworkClient* nwClient = gameClient->GetClient();
|
||||||
|
|
||||||
// Send the chosen mesh name
|
// Send the level information
|
||||||
Protocol_LobbyCreateGame lcg(obj->GetPlayer()->GetID(), "char_white.dan", obj->GetPlayer()->GetOrientation());
|
|
||||||
obj->GetClient()->Send(lcg);
|
|
||||||
|
|
||||||
// Send the player data only
|
|
||||||
for (unsigned int i = 0; i < this->clients.Capacity(); i++)
|
|
||||||
{
|
{
|
||||||
if(this->clients[i])
|
Protocol_LobbyCreateGame lcg((char)1, (char)0, this->description.mapName);
|
||||||
{
|
nwClient->Send(lcg);
|
||||||
IPlayerData* p = this->clients[i]->GetPlayer();
|
|
||||||
Protocol_ObjectCreate oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan");
|
|
||||||
//Protocol_ObjectCreatePlayer oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan");
|
|
||||||
this->clients[i]->GetClient()->Send(oc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
obj->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(0));
|
// Send the player data only
|
||||||
|
{
|
||||||
|
Protocol_ObjectCreatePlayer oc( playerData->GetPosition(), playerData->GetRotation(), playerData->GetScale(),
|
||||||
|
playerData->GetID(), true, playerData->GetTeamID(),
|
||||||
|
/*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan");
|
||||||
|
nwClient->Send(oc);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send information about other clients
|
||||||
|
{
|
||||||
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
||||||
|
{
|
||||||
|
if(clients[i])
|
||||||
|
{
|
||||||
|
IPlayerData* temp = clients[i]->GetPlayer();
|
||||||
|
Protocol_ObjectCreatePlayer oc( temp->GetPosition(), temp->GetRotation(), temp->GetScale(),
|
||||||
|
temp->GetID(), false, temp->GetTeamID(),
|
||||||
|
/*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan");
|
||||||
|
nwClient->Send(oc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: Need to be able to get the current gameplay data from the logic, to sync it with the client
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert the new client to the update list
|
||||||
|
{
|
||||||
|
bool added = false;
|
||||||
|
for (unsigned int i = 0; !added && i < this->clients.Size(); i++)
|
||||||
{
|
{
|
||||||
if(!clients[i])
|
if(!clients[i])
|
||||||
{
|
{
|
||||||
NetworkSession::clients[i] = client;
|
NetworkSession::clients[i] = networkClient;
|
||||||
clients[i] = obj;
|
clients[i] = gameClient;
|
||||||
return true;
|
added = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!added)
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameSession::CloseSession( bool dissconnectClients )
|
|
||||||
{
|
{
|
||||||
|
NetworkSession::clients.Push( networkClient );
|
||||||
|
clients.Push( gameClient );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Send the start signal
|
||||||
|
{
|
||||||
|
nwClient->Send(GameLogic::Protocol_LobbyStartGame(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameSession::CloseSession( bool dissconnectClients )
|
||||||
|
{
|
||||||
this->worker.Terminate();
|
this->worker.Terminate();
|
||||||
NetworkSession::CloseSession(true);
|
NetworkSession::CloseSession(true);
|
||||||
this->clients.Clear();
|
this->clients.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
}//End namespace DanBias
|
|
||||||
|
|
||||||
|
|
|
@ -133,13 +133,7 @@ namespace Oyster
|
||||||
*/
|
*/
|
||||||
virtual void DataRecieved(NetEvent<NetworkClient*, ClientEventArgs> e);
|
virtual void DataRecieved(NetEvent<NetworkClient*, ClientEventArgs> e);
|
||||||
|
|
||||||
/** ! Deprecate !
|
std::string GetIpAddress();
|
||||||
* Do not use this furthermore, instead use void DataRecieved(NetEvent<NetworkClient*, ClientEventArgs> e);
|
|
||||||
* @see DataRecieved
|
|
||||||
*/
|
|
||||||
//virtual void NetworkCallback(Oyster::Network::CustomNetProtocol& p);
|
|
||||||
|
|
||||||
virtual std::string GetIpAddress();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NetworkClient(const NetworkClient& obj);
|
NetworkClient(const NetworkClient& obj);
|
||||||
|
|
Loading…
Reference in New Issue