#ifndef HOSTJOIN_H_3456786 #define HOSTJOIN_H_3456786 #include "SDLsidekick.h" #include /* struct PlayerNode { PlayerNode *next; string Player_nick; IPaddress Player_IP; TCPsocket Player_TCPSOCK; }; */ void pre_game_client() { PlayerNode Client; //Sets up connecting to server SDLNet_ResolveHost(&Server_IP, Hosts_IP.c_str(), 1337); Client.Outbound=SDLNet_TCP_Open(&Server_IP); SDLNet_TCP_Send(Client.Outbound,My_nick.c_str(),My_nick.size()); sprintf(temphold,"%i",Client.Player_number); SDLNet_TCP_Recv(Client.Outbound,temphold,MAXLEN); Client.Player_number = atoi(temphold); SDL_WM_SetCaption(temphold, NULL); while(quit==false) { if( SDL_PollEvent( &event ) ) { switch (event.type) { case SDL_QUIT: { quit = true; break; } } } } } void pre_game_server() { //sets up the linked list PlayerNode *Root; PlayerNode *Conductor; Root = new PlayerNode; Root-> next = NULL; Conductor = Root; //Sets up server port listening SDLNet_ResolveHost(&Server_IP, NULL, 1337); Server_socket= SDLNet_TCP_Open(&Server_IP); while (quit == false) { //Testing //char Temphold[30]; //sprintf( Temphold, "%i", Player_count); //SDL_WM_SetCaption(Temphold, NULL); mouse_x = event.button.x; mouse_y = event.button.y; SDL_Flip( screen); SDL_Delay( 30 ); //Accepts the connection Conductor->Inbound = SDLNet_TCP_Accept(Server_socket); //If connection has come if(Conductor->Inbound!=NULL) { Conductor->Player_number=Player_count; SDLNet_TCP_Recv(Conductor->Inbound,temphold,MAXLEN); Conductor->Player_nick= Conductor->Player_nick + temphold; SDL_WM_SetCaption(Conductor->Player_nick.c_str(), NULL); sprintf(temphold,"%i",Conductor->Player_number); SDLNet_TCP_Send(Conductor->Inbound,temphold,MAXLEN); //Sets a new Node for the next player to connect to Conductor->next = new PlayerNode; Conductor=Conductor->next; Conductor->next=0; Player_count++; } if( SDL_PollEvent( &event ) ) { switch (event.type) { case SDL_QUIT: { quit = true; break; } } } } return; } void join_update_screen() { apply_surface( 0, 0, background, screen); apply_surface( 64*3, 64*3, HostJoin_menu, screen); apply_surface( 0, 480-64,back_button, screen); apply_surface( 0, -5, version, screen); } void host_update_screen() { apply_surface( 0, 0, background, screen); apply_surface( 64*3, 64*3, HostJoin_menu, screen); apply_surface( 0, 480-64,back_button, screen); apply_surface( 0, -5, version, screen); } void host_game() { SDL_FreeSurface(message); message=TTF_RenderText_Solid( font, Race_length.c_str(), textColor ); SDL_FreeSurface(HostJoin_menu); HostJoin_menu = load_image("Host Menu.bmp"); while (quit == false) { mouse_x = event.button.x; mouse_y = event.button.y; host_update_screen(); apply_surface(5*64+48, 3*64+18, message, screen); SDL_Flip( screen); SDL_Delay( 30 ); if( SDL_PollEvent( &event ) ) { //Checks if user wants to quit switch (event.type) { case SDL_QUIT: { quit = true; break; } case SDL_MOUSEBUTTONDOWN: { if( event.button.button == SDL_BUTTON_LEFT ) { //MOUSE X //MOUSE Y //IP input if( (mouse_x>3*64 && mouse_x<7*64) && (mouse_y > 3*64 && mouse_y < 4*64) ) { change_string( &Race_length, host_update_screen,4,5*64+48, 3*64+18); } //MOUSE X //MOUSE Y //Pre Game Server if( (mouse_x>3*64 && mouse_x<7*64) && (mouse_y > 4*64 && mouse_y < 5*64) ) { pre_game_server(); } //MOUSE X //MOUSE Y //go back if( (mouse_x>0 && mouse_x<64) && (mouse_y > 480-64 && mouse_y < 480) ) { return; } } } } } } } void join_game() { SDL_FreeSurface(message); message=TTF_RenderText_Solid( font, Hosts_IP.c_str(), textColor ); SDL_FreeSurface(HostJoin_menu); HostJoin_menu = load_image("Join Menu.bmp"); while (quit == false) { mouse_x = event.button.x; mouse_y = event.button.y; join_update_screen(); apply_surface(3*64+48, 3*64+18, message, screen); SDL_Flip( screen); SDL_Delay( 30 ); if( SDL_PollEvent( &event ) ) { //Checks if user wants to quit switch (event.type) { case SDL_QUIT: { quit = true; break; } case SDL_KEYDOWN: { switch( event.key.keysym.sym) { case SDLK_ESCAPE: return ; } } case SDL_MOUSEBUTTONDOWN: { if( event.button.button == SDL_BUTTON_LEFT ) { //MOUSE X //MOUSE Y //IP input if( (mouse_x>3*64 && mouse_x<7*64) && (mouse_y > 3*64 && mouse_y < 4*64) ) { change_string(&Hosts_IP, join_update_screen , 15, 3*64+48, 3*64+18); } //MOUSE X //MOUSE Y //Connect to server if( (mouse_x>3*64 && mouse_x<7*64) && (mouse_y > 4*64 && mouse_y < 5*64) ) { pre_game_client(); } //MOUSE X //MOUSE Y //go back if( (mouse_x>0 && mouse_x<64) && (mouse_y > 480-64 && mouse_y < 480) ) { return; } } } } } } return; } #endif