00001
00002
00003
00004
00005
00006 #ifndef NETLOBBY_H_
00007 #define NETLOBBY_H_
00008
00009 #include <boost/asio.hpp>
00010 #include <boost/thread.hpp>
00011 #include <messages.h>
00012 #include <listener.h>
00013 #include <sender.h>
00014 #include <boost/date_time/posix_time/posix_time.hpp>
00015 #include <netCommon.h>
00016
00017 using namespace boost::posix_time;
00018 using boost::asio::ip::udp;
00019
00020 namespace FastEcslent {
00021
00022 class Engine;
00023
00024 class NetLobby {
00025
00026 private:
00027 boost::thread netThread;
00028
00029 int TICK_SLEEP_TIME;
00030
00031 ptime startTime;
00032
00033 boost::posix_time::milliseconds *sleepTime;
00034 boost::posix_time::milliseconds *lobbySleepTime;
00035
00036 NetCommon *netCommon;
00037
00038 Engine* engine;
00039 Listener* listener;
00040 Sender* sender;
00041
00042 void init();
00043 void runThread();
00044 LobbyServer* fillLobbyClients(const std::string &gameName, const std::string &ip, int port, int side, int player, int slot, bool isHost);
00045
00046 void handleClientMessages();
00047 void handleServerMessages();
00048
00049 void clientTick();
00050 void serverTick();
00051
00052
00053 void sendLobbyServerInfo();
00054 void updateLobbyServer(Message *m);
00055
00056
00057 void joinRequest(Message *m);
00058 void clientEnter(Message *m);
00059 void serverExit(Message *m);
00060 void clientExit(Message *m);
00061 void clientSwap(Message *m);
00062 void startByRemote(Message *m);
00063
00064 public:
00065 std::string myIPAddress;
00066
00067 int port;
00068 bool quit;
00069
00070 NetLobby(Engine* eng);
00071
00072 void run();
00073
00074 void sendLobbyClientResponse(const std::string &clientIP, int port, int side, int player);
00075 void lobbyStart();
00076
00077 void lobbyJoinGame(const std::string &ip, int port);
00078 void lobbyExitGame(const std::string &ip, int port);
00079 void lobbySlotSwapReq(const std::string &serverip, int port, int newpos, int oldpos, int newside, int newplayer);
00080 virtual ~NetLobby();
00081 };
00082
00083 }
00084
00085 #endif