game_server.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef GAME_SERVER_H
  2. #define GAME_SERVER_H
  3. #include <time.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <arpa/inet.h>
  9. #include <sys/select.h>
  10. #include <signal.h>
  11. #include <sys/time.h>
  12. #ifndef PORT
  13. #define PORT 8888
  14. #endif
  15. #define NAME 0
  16. #define COMMAND 1
  17. #define DELIM " \n"
  18. #define TIMER_TICK 120
  19. #define MAX_NAME 10
  20. #define INPUT_ARG_MAX_NUM 10
  21. #define BUFFER_SIZE 1024
  22. typedef struct client {
  23. int fd;
  24. int state;
  25. char name[MAX_NAME];
  26. char buf[BUFFER_SIZE];
  27. int inbuf;
  28. struct client *next;
  29. } Client;
  30. typedef struct player {
  31. char name[MAX_NAME];
  32. int max_score;
  33. int total_games;
  34. int total_score;
  35. struct player *next;
  36. } Player;
  37. //int create_player(const char *name, Player **player_ptr_add);
  38. //Player *find_player(const char *name, const Player *head);
  39. int setup (void);
  40. void timer_handler(int sig);
  41. void new_connection(int listenfd) ;
  42. void add_client(int fd, struct in_addr addr);
  43. void remove_client(int fd);
  44. void sendclient(Client *p, char *msg);
  45. void receiveclient(Client *p, int flag);
  46. void interpret_message(Client *p, int flag);
  47. int parse_line(Client *p, int flag);
  48. int do_command(struct client * p, int cmd_argc, char **cmd_argv, int flag);
  49. int find_network_newline(char *buf, int inbuf);
  50. #endif