My Project
 All Classes
Listener.h
1 #pragma once
2 
3 #include <ClanLib/core.h>
4 #include <ClanLib/network.h>
5 #include "direction.h"
6 
7 class Playground;
8 class ServerUser;
9 class LvlCount;
10 class Controller;
11 
12 
13 class Listener
14 {
15  public:
16  Listener(Playground *pg, LvlCount *cnt, Controller *ctrl, CL_Mutex *pg_mutex, CL_String8 _port);
17  void exec();
18 
19  private:
20  void on_client_connected(CL_NetGameConnection *connection);
21  void on_client_disconnected(CL_NetGameConnection *connection);
22 
23  void on_event_received(CL_NetGameConnection *connection, const CL_NetGameEvent &e);
24 
25  void on_event_say_name(const CL_NetGameEvent &e, ServerUser *user);
26  void on_event_gamestart_request(const CL_NetGameEvent &e, ServerUser *user);
27  void on_event_key_input(const CL_NetGameEvent &e, ServerUser *user);
28 
29  void send_data();
30 
31  // verbundene Clients werden in einer Map gespeichert
32  ServerUser *find_user(CL_NetGameConnection *connection);
33  bool mapContainsUser(CL_String username);
34 
35 
36  private:
37  Playground *game;
38  CL_Mutex *game_mutex;
39  LvlCount *lvlcnt;
40  Controller *super;
41  CL_String8 port;
42  CL_String8 winName;
43 
44  CL_NetGameServer network_server;
45  CL_SlotContainer slots;
46 
47  bool locked;
48  CL_String8 getUserByChar(char c);
49 
50  CL_NetGameEventDispatcher_v1<ServerUser*> name_event;
51  CL_NetGameEventDispatcher_v1<ServerUser*> game_event;
52 
53  std::map<CL_NetGameConnection *, ServerUser *> users;
54 };