source: abuse/tags/pd/macabuse/src/net/unix/gserver.hpp @ 49

Last change on this file since 49 was 49, checked in by Sam Hocevar, 11 years ago
  • Imported original public domain release, for future reference.
File size: 2.1 KB
Line 
1#ifndef __GSERVER_HPP_
2#define __GSERVER_HPP_
3
4#define MAX_JOINERS 32  // maximum clients that can join at the same time
5
6
7#include "sock.hpp"
8#include "ghandler.hpp"
9
10class game_server : public game_handler
11{
12  class player_client
13  {
14    unsigned char flags;
15    enum { Has_joined=1,
16           Wait_reload=2,
17           Wait_input=4,
18           Need_reload_start_ok=8,
19           Delete_me=16 };
20    int get_flag(int flag)         { return flags&flag; }
21    void set_flag(int flag, int x) { if (x) flags|=flag; else flags&=~flag; }
22
23    public :
24    int has_joined() { return get_flag(Has_joined); }
25    void set_has_joined(int x) { set_flag(Has_joined,x); }
26
27    int wait_input() { return get_flag(Wait_input); }
28    void set_wait_input(int x) { set_flag(Wait_input,x); }
29
30    int wait_reload() { return get_flag(Wait_reload); }
31    void set_wait_reload(int x) { set_flag(Wait_reload,x); }
32
33    int delete_me() { return get_flag(Delete_me); }
34    void set_delete_me(int x) { set_flag(Delete_me,x); }
35
36    int need_reload_start_ok() { return get_flag(Need_reload_start_ok); }
37    void set_need_reload_start_ok(int x) { set_flag(Need_reload_start_ok,x); }
38
39    net_socket *comm;
40    int client_id;
41    net_address *data_address;
42    player_client *next;
43    player_client(int client_id, net_socket *comm, net_address *data_address, player_client *next) :
44      client_id(client_id), comm(comm), data_address(data_address), next(next)
45      {
46        flags=0;
47        set_wait_input(1);
48        comm->read_selectable();
49      };
50    ~player_client();
51  } ;
52
53  player_client *player_list;
54  int waiting_server_input, reload_state;
55
56  void add_client_input(char *buf, int size, player_client *c);
57  void check_collection_complete();
58  void check_reload_wait();
59  int process_client_command(player_client *c);
60  int isa_client(int client_id);
61  public :
62  virtual void game_start_wait();
63  int total_players();
64  int process_net();
65  void add_engine_input();
66  int input_missing();
67  virtual int start_reload();
68  virtual int end_reload(int disconnect=0);
69  virtual int add_client(int type, net_socket *sock, net_address *from);
70  virtual int kill_slackers();
71  virtual int quit();
72  game_server();
73  ~game_server();
74} ;
75
76#endif
Note: See TracBrowser for help on using the repository browser.