extern int proto_server_init(void) { int i; int rc; proto_session_init(&Proto_Server.EventSession); proto_server_set_session_lost_handler( proto_session_lost_default_handler); for (i=PROTO_MT_REQ_BASE_RESERVED_FIRST+1; i<PROTO_MT_REQ_BASE_RESERVED_LAST; i++) { Proto_Server.base_req_handlers[i] = proto_server_mt_null_handler; } for (i=0; i<PROTO_SERVER_MAX_EVENT_SUBSCRIBERS; i++) { Proto_Server.EventSubscribers[i]=-1; } Proto_Server.EventNumSubscribers=0; Proto_Server.EventLastSubscriber=0; pthread_mutex_init(&Proto_Server.EventSubscribersLock, 0); rc=net_setup_listen_socket(&(Proto_Server.RPCListenFD), &(Proto_Server.RPCPort)); if (rc==0) { fprintf(stderr, "proto_server_init: net_setup_listen_socket: FAILED for RPCPort\n"); return -1; } Proto_Server.EventPort = Proto_Server.RPCPort + 1; rc=net_setup_listen_socket(&(Proto_Server.EventListenFD), &(Proto_Server.EventPort)); if (rc==0) { fprintf(stderr, "proto_server_init: net_setup_listen_socket: FAILED for EventPort=%d\n", Proto_Server.EventPort); return -2; } if (pthread_create(&(Proto_Server.EventListenTid), NULL, &proto_server_event_listen, NULL) !=0) { fprintf(stderr, "proto_server_init: pthread_create: create EventListen thread failed\n"); perror("pthread_createt:"); return -3; } return 0; }
int main(int argc, char **argv) { int listenfd, port=0; long connfd; pthread_t tid; bzero(&globals, sizeof(globals)); if (net_setup_listen_socket(&listenfd,&port)!=1) { fprintf(stderr, "net_setup_listen_socket FAILED!\n"); exit(-1); } printf("listening on port=%d\n", port); if (net_listen(listenfd) < 0) { fprintf(stderr, "Error: server listen failed (%d)\n", errno); exit(-1); } for (;;) { connfd = net_accept(listenfd); if (connfd < 0) { fprintf(stderr, "Error: server accept failed (%d)\n", errno); } else { //EXPLAIN WHAT IS HAPPENING HERE IN YOUR LOG pthread_create(&tid, NULL, &doit, (void *)connfd); } } VPRINTF("Exiting\n"); }
extern int proto_server_init(void) { int i; int rc; proto_session_init(&Proto_Server.EventSession); proto_server_set_session_lost_handler( proto_session_lost_default_handler); //for (i=PROTO_MT_REQ_BASE_RESERVED_FIRST+1; // i<PROTO_MT_REQ_BASE_RESERVED_LAST; i++) { //proto_server_set_req_handler(i, proto_server_mt_null_handler); //proto_server_set_req_handler(i, proto_server_mt_join_game_handler); //} // set_up_actual_game rpc handlers proto_server_set_req_handler( PROTO_MT_REQ_BASE_HELLO, proto_server_mt_join_game_handler); proto_server_set_req_handler( PROTO_MT_REQ_BASE_MOVE, proto_server_mt_move_handler); proto_server_set_req_handler( PROTO_MT_REQ_ITEM_ACTION, proto_server_mt_item_action_handler); proto_server_set_req_handler( PROTO_MT_REQ_BASE_GOODBYE, proto_server_mt_leave_game_handler); proto_server_set_req_handler( PROTO_MT_REQ_NUM_HOME , proto_server_mt_numhome_handler ); proto_server_set_req_handler( PROTO_MT_REQ_NUM_JAIL , proto_server_mt_numjail_handler ); proto_server_set_req_handler( PROTO_MT_REQ_NUM_WALL , proto_server_mt_numwall_handler ); proto_server_set_req_handler( PROTO_MT_REQ_NUM_FLOOR, proto_server_mt_numfloor_handler ); proto_server_set_req_handler( PROTO_MT_REQ_MAP_DIM , proto_server_mt_dim_handler ); proto_server_set_req_handler( PROTO_MT_REQ_CELL_INFO, proto_server_mt_cinfo_handler ); proto_server_set_req_handler( PROTO_MT_REQ_MAP_DUMP , proto_server_mt_dump_handler ); //pthread_mutex_lock(&gameMapVersion_mutex); //gameMapVersion.raw = 0; //pthread_mutex_unlock(&gameMapVersion_mutex); for (i = 0; i < PROTO_SERVER_MAX_EVENT_SUBSCRIBERS; i++) { Proto_Server.EventSubscribers[i] = -1; } Proto_Server.EventNumSubscribers = 0; Proto_Server.EventLastSubscriber = 0; pthread_mutex_init(&Proto_Server.EventSubscribersLock, 0); rc = net_setup_listen_socket(&(Proto_Server.RPCListenFD), &(Proto_Server.RPCPort)); if (rc == 0) { fprintf(stderr, "prot_server_init: net_setup_listen_socket: FAILED for RPCPort\n"); return -1; } Proto_Server.EventPort = Proto_Server.RPCPort + 1; rc = net_setup_listen_socket(&(Proto_Server.EventListenFD), &(Proto_Server.EventPort)); if (rc == 0) { fprintf(stderr, "proto_server_init: net_setup_listen_socket: FAILED for EventPort=%d\n", Proto_Server.EventPort); return -2; } if (pthread_create(&(Proto_Server.EventListenTid), NULL, &proto_server_event_listen, NULL) != 0) { fprintf(stderr, "proto_server_init: pthread_create: create EventListen thread failed\n"); perror("pthread_createt:"); return -3; } return 0; }
extern int proto_server_init(void){ int i; int rc; int dim; gamefull=flag1found=flag2found=flag1home1=flag2home1=flag1home2= flag2home2=numplayershome1=numplayershome2=numPlayers1=numPlayers2 = 0; if((Server_Map = map_init(MAP_NAME)) == NULL) return -1; dim = Server_Map->dim; if((Server_Gamestate = gamestate_create()) == NULL){ fprintf(stderr, "could not create gamestate\n"); return -1; } if((Server_ObjectMap = objectmap_create(Server_Map, Server_Gamestate)) == NULL){ fprintf(stderr, "could not load map\n"); return -1; } pidx = 0; nextTeam = TEAM1; proto_session_init(&Proto_Server.EventSession); proto_server_set_session_lost_handler(proto_session_lost_default_handler); for (i=PROTO_MT_REQ_BASE_RESERVED_FIRST+1; i<PROTO_MT_REQ_BASE_RESERVED_LAST; i++) { if(i == PROTO_MT_REQ_BASE_HELLO) proto_server_set_req_handler(i,proto_server_hello_handler); else if(i == PROTO_MT_REQ_BASE_MOVE) proto_server_set_req_handler(i,proto_server_move_handler); // if(i == PROTO_MT_REQ_BASE_QUERY) // proto_server_set_req_handler(i,proto_server_query_handler); else if(i == PROTO_MT_REQ_BASE_DUMP) proto_server_set_req_handler(i,proto_server_dump_handler); else if(i == PROTO_MT_REQ_BASE_CINFO) proto_server_set_req_handler(i,proto_server_cinfo_handler); else if(i == PROTO_MT_REQ_BASE_GOODBYE) proto_server_set_req_handler(i,proto_server_goodbye_handler); else proto_server_set_req_handler(i, proto_server_mt_null_handler); } for (i=0; i<PROTO_SERVER_MAX_EVENT_SUBSCRIBERS; i++) { Proto_Server.EventSubscribers[i]=-1; } Proto_Server.EventNumSubscribers=0; Proto_Server.EventLastSubscriber=0; pthread_mutex_init(&Proto_Server.EventSubscribersLock, 0); rc=net_setup_listen_socket(&(Proto_Server.RPCListenFD), &(Proto_Server.RPCPort)); if (rc==0) { fprintf(stderr, "prot_server_init: net_setup_listen_socket: FAILED for RPCPort\n"); return -1; } Proto_Server.EventPort = Proto_Server.RPCPort + 1; rc=net_setup_listen_socket(&(Proto_Server.EventListenFD), &(Proto_Server.EventPort)); if (rc==0) { fprintf(stderr, "proto_server_init: net_setup_listen_socket: FAILED for EventPort=%d\n", Proto_Server.EventPort); return -2; } if (pthread_create(&(Proto_Server.EventListenTid), NULL, &proto_server_event_listen, NULL) !=0) { fprintf(stderr, "proto_server_init: pthread_create: create EventListen thread failed\n"); perror("pthread_createt:"); return -3; } return 0; }