utils.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef UTILS_H
  2. #define UTILS_H
  3. #define TIME_INTERVAL 60
  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 8888
  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. //typedef struct client {
  24. //// int fd;
  25. //// int state; // either NAME or COMMAND
  26. //// char name[MAX_NAME];
  27. //// char buf[BUFFER_SIZE]; // each client has its own buffer
  28. //// int inbuf; // and a personal pointer to the current place in buffer
  29. //// struct client *next;
  30. ////} Client;
  31. ////
  32. ////typedef struct player {
  33. //// char name[MAX_NAME];
  34. //// int max_score;
  35. //// int total_games;
  36. //// int total_score;
  37. //// struct player *next;
  38. ////} Player;
  39. //
  40. //int create_player(const char *name, Player **player_ptr_add);
  41. //Player *find_player(const char *name, const Player *head);
  42. int setup (void);
  43. void timer_handler(int sig);
  44. void new_connection(int listenfd) ;
  45. void add_client(int fd, struct in_addr addr);
  46. void remove_client(int fd);
  47. ////void sendclient(Client *p, char *msg);
  48. ////void receiveclient(Client *p);
  49. ////void interpret_message(Client *p);
  50. ////int parse_line(Client *p);
  51. ////int do_command(struct client * p, int cmd_argc, char **cmd_argv);
  52. int find_network_newline(char *buf, int inbuf);
  53. //
  54. typedef struct user {
  55. char name[9];
  56. int max_score;
  57. int total_games;
  58. int total_score;
  59. struct user * next;
  60. } User;
  61. User *head;
  62. User *current;
  63. User *array_end;
  64. int board[16];
  65. int login();
  66. int verify_word(char* word);
  67. void scoreboard();
  68. int initialzie_dictionary();
  69. void update_scores(int new_score, int old_score);
  70. void free_dictionaries();
  71. void free_players();
  72. void reset_words();
  73. int write_users();
  74. int read_users();
  75. #endif