source: abuse/trunk/src/net/engine.h @ 651

Last change on this file since 651 was 481, checked in by Sam Hocevar, 12 years ago

Fuck the history, I'm renaming all .hpp files to .h for my own sanity.

  • Property svn:keywords set to Id
File size: 2.0 KB
RevLine 
[2]1// engine.c is the what comminicates with the abuse engine
2
3#ifndef __ENGINE_HPP_
4#define __ENGINE_HPP_
5
[481]6#include "../inc/netface.h"
[2]7#include <stdio.h>
8#include <stdlib.h>
9#include <fcntl.h>
10#include <unistd.h>
11#include <sys/ioctl.h>
12#include <sys/stat.h>
13#include <sys/types.h>
14#include <sys/time.h>
15#include <string.h>
16#include <signal.h>
17#include <sys/socket.h>
18#include <netinet/in.h>
19#include <sys/types.h>
20#include <sys/ipc.h>
21#include <sys/shm.h>
22#include <bstring.h>
23#include <netdb.h>
24
25
26#define DEFAULT_COMM_PORT 20202
27#define DEFAULT_GAME_PORT 20203
[124]28#define MAX_JOINERS 32  // maximum clients that can join at the same time
[2]29
30
31extern int no_security;
32extern int driver_out_fd,driver_in_fd;
33struct base_memory_struct;
34extern base_memory_struct *base;
35
36
37extern fd_set master_set;        // list of sockets to block for
38extern fd_set master_write_set;  // set a socket here if you detect a write_full
39
40
41void comm_failed();              // call if problems talking to engine
42void mdie(char *reason);         // call if general net problems
43
44
45#define real2shm(type,ptr) (ptr==NULL ? NULL : ((type *)((char *)(ptr)-(char *)base)))
46#define shm2real(type,ptr) (ptr==NULL ? NULL : ((type *)((long)(ptr)+(long)(base))))
47
48class client
49{
50public :
51  int socket_fd;
52  int data_fd;
53  int client_id;       // index into client_struct
54  int has_joined;
55  int wait_reload;
56  int wait_input;
57  int delete_me;
58  struct sockaddr_in data_address;  // where to send game data
[124]59
[2]60  client *next;
[124]61  client(int sock, int id, client *Next)
62  {
[2]63    data_fd=-1;
[124]64    socket_fd=sock;
65    client_id=id;
66    next=Next;
67    has_joined=0;
[2]68    delete_me=0;
69    wait_reload=0;
70    wait_input=1;
71    FD_SET(socket_fd,&master_set);   // set in case socket dies
72  }
73  ~client()
74  {
[124]75    close(socket_fd);
[2]76    FD_CLR(socket_fd,&master_set);
77    if (data_fd>0)
78      close(data_fd);
79  } ;
80} ;
81
82extern client *first_client;    // list of clients
83int connect_to_server(char *&server_name, int def_port=DEFAULT_COMM_PORT, int stream_type=SOCK_STREAM, int force_port=0);  // -1 on failure
84
85#endif
86
87
88
Note: See TracBrowser for help on using the repository browser.