diff --git a/Code/Game/DanBiasLauncher/Launcher.cpp b/Code/Game/DanBiasLauncher/Launcher.cpp index 2c3873cb..9df3a255 100644 --- a/Code/Game/DanBiasLauncher/Launcher.cpp +++ b/Code/Game/DanBiasLauncher/Launcher.cpp @@ -6,7 +6,7 @@ #include #include "DanBiasServerAPI.h" -//#include "DanBiasGame.h" +#include "DanBiasGame.h" int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdShow) diff --git a/Code/Game/DanBiasServer/ServerObjects/ClientObject.cpp b/Code/Game/DanBiasServer/ServerObjects/ClientObject.cpp index c9452b45..c8a259ad 100644 --- a/Code/Game/DanBiasServer/ServerObjects/ClientObject.cpp +++ b/Code/Game/DanBiasServer/ServerObjects/ClientObject.cpp @@ -28,6 +28,7 @@ Oyster::Network::NetworkClient* ClientObject::NetClient_Object() void ClientObject::ProtocolRecievedCallback(Oyster::Network::CustomNetProtocol& protocol) { + //this->client->Send(&protocol); if(!this->box) return; NetworkSession::NetEvent _event; diff --git a/Code/Game/DanBiasServer/ServerObjects/NetworkSession.cpp b/Code/Game/DanBiasServer/ServerObjects/NetworkSession.cpp index c33af5e0..1e64642d 100644 --- a/Code/Game/DanBiasServer/ServerObjects/NetworkSession.cpp +++ b/Code/Game/DanBiasServer/ServerObjects/NetworkSession.cpp @@ -3,6 +3,8 @@ #include "NetworkSession.h" #include +static std::mutex ClientListLock; + namespace DanBias { NetworkSession::NetworkSession() @@ -16,16 +18,27 @@ namespace DanBias void NetworkSession::AttachClient(Utility::DynamicMemory::SmartPointer client) { - for (unsigned int i = 0; i < this->clients.size(); i++) + while (!ClientListLock.try_lock()); //Possible Deadlock + + int k = -1; + for (unsigned int i = 0; (k == -1) && i < this->clients.size(); i++) { if(!this->clients[i]) - { - this->clients[i] = client; - this->clients[i]->SetPostbox(&this->box); - return; - } + k = i; } - this->clients.push_back(client); + + if(k == -1) + { + this->clients.push_back(client); + this->clients[this->clients.size() - 1]->SetPostbox(&this->box); + } + else + { + this->clients[k]->SetPostbox(&this->box); + } + + ClientListLock.unlock(); + } void NetworkSession::DetachClient(Oyster::Network::NetworkClient* client) diff --git a/Code/Misc/Thread/OysterThread_Impl.cpp b/Code/Misc/Thread/OysterThread_Impl.cpp index f4ff458c..cbc4b8ea 100644 --- a/Code/Misc/Thread/OysterThread_Impl.cpp +++ b/Code/Misc/Thread/OysterThread_Impl.cpp @@ -118,7 +118,8 @@ theBegining: std::this_thread::sleep_for(std::chrono::milliseconds(1)); break; case Oyster::Thread::OYSTER_THREAD_PRIORITY_3: - std::this_thread::yield(); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + //std::this_thread::yield(); break; } if(w->owner) diff --git a/Code/Network/NetworkAPI/NetworkCallbackHelper.h b/Code/Network/NetworkAPI/NetworkCallbackHelper.h index b088ea5c..40c66899 100644 --- a/Code/Network/NetworkAPI/NetworkCallbackHelper.h +++ b/Code/Network/NetworkAPI/NetworkCallbackHelper.h @@ -35,6 +35,7 @@ namespace Oyster struct ProtocolRecieverObject { virtual void ProtocolRecievedCallback(CustomNetProtocol& protocol) = 0; + virtual void DisconnectedCallback(CustomNetProtocol& protocol) { }; }; union RecieverObject diff --git a/Code/Network/NetworkAPI/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp index 69b22380..4cd1fe3f 100644 --- a/Code/Network/NetworkAPI/NetworkClient.cpp +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -238,6 +238,11 @@ void NetworkClient::Send(CustomProtocolObject& protocol) this->privateData->Send(protocol.GetProtocol()); } +void NetworkClient::Send(CustomNetProtocol* protocol) +{ + this->privateData->Send(protocol); +} + void NetworkClient::SetRecieverObject(RecieverObject recvObj, NetworkProtocolCallbackType type) { if (type == NetworkProtocolCallbackType_Unknown) return; //It should probably still be set even if it is unknown. diff --git a/Code/Network/NetworkAPI/NetworkClient.h b/Code/Network/NetworkAPI/NetworkClient.h index e77667a8..533ff23e 100644 --- a/Code/Network/NetworkAPI/NetworkClient.h +++ b/Code/Network/NetworkAPI/NetworkClient.h @@ -40,6 +40,7 @@ namespace Oyster //Adds the protocol to the queue of protocols to be sent. void Send(CustomProtocolObject& protocol); + void Send(CustomNetProtocol* protocol); void SetRecieverObject(RecieverObject recvObj, NetworkProtocolCallbackType type); diff --git a/Code/Network/NetworkDependencies/Packing.cpp b/Code/Network/NetworkDependencies/Packing.cpp index b6903a0a..5728cabe 100644 --- a/Code/Network/NetworkDependencies/Packing.cpp +++ b/Code/Network/NetworkDependencies/Packing.cpp @@ -169,7 +169,7 @@ namespace Oyster //bool (1-bit) bool Unpackb(unsigned char buffer[]) { - return buffer; + return *buffer; } //char (8-bit)