game_server.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //ready
  2. #ifndef GAME_SERVER_H
  3. #define GAME_SERVER_H
  4. #include <time.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8. #include <unistd.h>
  9. #include <arpa/inet.h>
  10. #include <sys/select.h>
  11. #include <signal.h>
  12. #include <sys/time.h>
  13. #ifndef PORT
  14. #define PORT 7200
  15. #endif
  16. #define NAME 0 //reflects 2 states of client connection: 0 - identification, 1 - identified, can enter commands
  17. #define COMMAND 1
  18. #define DELIM " \n"
  19. #define TIMER_TICK 120
  20. #define MAX_NAME 10 // Max playername length
  21. #define INPUT_ARG_MAX_NUM 10
  22. #define BUFFER_SIZE 1024
  23. //extern char board[4][4];
  24. //Node for the linked list which stores currently connected clients
  25. typedef struct client {
  26. int fd;
  27. int state; // either NAME or COMMAND
  28. char name[MAX_NAME];
  29. char buf[BUFFER_SIZE]; // each client has its own buffer
  30. int inbuf; // and a personal pointer to the current place in buffer
  31. struct client *next;
  32. } Client;
  33. //Node for linked list which stores all players ever played - these are never removed
  34. typedef struct player {
  35. char name[MAX_NAME];
  36. int max_score;
  37. int total_games;
  38. int total_score;
  39. struct player *next;
  40. } Player;
  41. int create_player(const char *name, Player **player_ptr_add);
  42. Player *find_player(const char *name, Player *head);
  43. int setup (void);
  44. void timer_handler(int sig);
  45. /* accept new connection and calls add_client */
  46. void new_connection(int listenfd) ;
  47. /* Sets up Client fields, add to the list, and ask for the name */
  48. void add_client(int fd, struct in_addr addr);
  49. /* remove client from the list */
  50. void remove_client(int fd);
  51. void sendclient(Client *p, char *msg);
  52. void receiveclient(Client *p);
  53. void interpret_message(Client *p);
  54. int parse_line(Client *p);
  55. int do_command(struct client * p, int cmd_argc, char **cmd_argv);
  56. int find_network_newline(char *buf, int inbuf);
  57. //void generate_board();
  58. int WordInDictionary(char * word);
  59. #endif