summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-04-16 23:31:54 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-04-16 23:31:54 +0000
commit5478d27cb1affe4c7be40dab32058ada95258a1f (patch)
tree820fa7786c31e0c99a9e7b51ad58faffeac1d9e7 /src
parent3f86b3120f9b9b651f099d94d92e64f682fd8f31 (diff)
downloadmanaserv-5478d27cb1affe4c7be40dab32058ada95258a1f.tar.gz
manaserv-5478d27cb1affe4c7be40dab32058ada95258a1f.tar.bz2
manaserv-5478d27cb1affe4c7be40dab32058ada95258a1f.tar.xz
manaserv-5478d27cb1affe4c7be40dab32058ada95258a1f.zip
Added a bit of listening code.
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp6
-rw-r--r--src/netsession.cpp31
2 files changed, 32 insertions, 5 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 454885d9..19e95520 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -103,8 +103,8 @@ int main(int argc, char *argv[])
//connectionHandler->registerHandler(C2S_LOGIN, accountHandler);
printf("The Mana World Server v0.0.1\n");
- printf("Listening...\n");
session->startListen(connectionHandler, SERVER_PORT);
+ printf("Listening on port %d...\n", SERVER_PORT);
SDL_Event event;
@@ -131,8 +131,8 @@ int main(int argc, char *argv[])
}
}
- // We know about only about 10 events will happen per second, so give
- // the CPU a break for a while.
+ // We know only about 10 events will happen per second,
+ // so give the CPU a break for a while.
SDL_Delay(100);
}
diff --git a/src/netsession.cpp b/src/netsession.cpp
index 3ad8da1a..a617c105 100644
--- a/src/netsession.cpp
+++ b/src/netsession.cpp
@@ -23,10 +23,35 @@
#include "netsession.h"
+#define MAX_CLIENTS 1024
+
int startListenThread(void *data)
{
- // So who will do the actual listening now?
+ ListenThreadData *ltd = (ListenThreadData*)data;
+
+ // Allocate a socket set
+ SDLNet_SocketSet set = SDLNet_AllocSocketSet(MAX_CLIENTS);
+ if (!set) {
+ printf("SDLNet_AllocSocketSet: %s\n", SDLNet_GetError());
+ exit(1);
+ }
+
+ // Add the server socket to the socket set
+ if (SDLNet_TCP_AddSocket(set, ltd->socket) < 0) {
+ printf("SDLNet_AddSocket: %s\n", SDLNet_GetError());
+ exit(1);
+ }
+
+ // Keep checking for socket activity while running
+ while (ltd->running)
+ {
+ int numready = SDLNet_CheckSockets(set, 1000);
+ printf("numready: %d\n", numready);
+ }
+
+ SDLNet_FreeSocketSet(set);
+
return 0;
}
@@ -46,7 +71,7 @@ void NetSession::startListen(ConnectionHandler *handler, Uint16 port)
// will call connect/disconnect events on the given ConnectionHandler and
// will cut incoming data into Packets and send them there too.
- ListenThreadData *data = new ListenThreadData;
+ ListenThreadData *data = new ListenThreadData();
data->address.host = INADDR_ANY;
data->address.port = port;
@@ -86,6 +111,8 @@ void NetSession::stopListen(Uint16 port)
// disconnect notifications about all the connected clients.
SDL_WaitThread(data->thread, NULL);
SDLNet_TCP_Close(data->socket);
+ delete data;
+ listeners.erase(threadDataI);
}
else
{