Smooth connection and disconnection complete

The clients can connect and disconnect from the server with known no
issues. There is no way to shutdown the server yet, but it might be
possible to kick someone else from the server soon.
This commit is contained in:
Kayne Ruse
2013-06-18 16:21:42 +10:00
parent e833129983
commit 33474cc6c0
14 changed files with 177 additions and 41 deletions
+9
View File
@@ -0,0 +1,9 @@
#include "defines.hpp"
#include <cstdio>
std::string itos(int i) {
char buffer[20];
snprintf(buffer, 20, "%d", i);
return std::string(buffer);
}
+3
View File
@@ -2,10 +2,13 @@
#define DEFINES_HPP
#include <chrono>
#include <string>
#define GAME_CHANNEL 0
#define CHAT_CHANNEL 1
typedef std::chrono::high_resolution_clock Clock;
std::string itos(int i);
#endif
+11 -3
View File
@@ -31,7 +31,7 @@ static int networkQueue(void*) {
return 0;
}
void BeginQueueThread() {
void beginQueueThread() {
if (running) {
return;
}
@@ -41,7 +41,7 @@ void BeginQueueThread() {
}
}
void EndQueueThread() {
void endQueueThread() {
if (!running) {
return;
}
@@ -50,7 +50,7 @@ void EndQueueThread() {
queueThread = nullptr;
}
void KillQueueThread() {
void killQueueThread() {
if (!running) {
return;
}
@@ -78,4 +78,12 @@ Packet popNetworkPacket() {
}
SDL_SemPost(lock);
return p;
}
void flushNetworkQueue() {
UDPNetworkUtility* netUtil = ServiceLocator<UDPNetworkUtility>::Get();
SDL_SemWait(lock);
while(netUtil->Receive());
queue.clear();
SDL_SemPost(lock);
}
+4 -3
View File
@@ -3,10 +3,11 @@
#include "packet_type.hpp"
void BeginQueueThread();
void EndQueueThread();
void KillQueueThread();
void beginQueueThread();
void endQueueThread();
void killQueueThread();
Packet peekNetworkPacket();
Packet popNetworkPacket();
void flushNetworkQueue();
#endif
+1
View File
@@ -62,6 +62,7 @@ struct JoinResponse {
struct Disconnect {
Metadata meta;
int clientIndex;
};
struct Synchronize {