I'm still alive... Without time... but still on project. Release 0.5... 0.6 will have network... Will not accept directly keyboard and mouse action, but game action. mostly because cvs syncronization problems. But this have the biggest problem. I need to change a lot of files... when I tried to update with the cvs code...it gives me problems. I think I already sended 0.4 wormux version with network, with lot of errors and it miss many thinks. The server... I think it can be on both modes... but if server is independent it will be more easy to update, to have several wormuz players on the same game.... By other hand it will need a lot of time...
Here I put network.h and network.h with main functions. Far from working well, and it will need a lot of work :( this functions It's an exemple how to use it: bool Dynamite::Tire (shoot *Shoot=NULL) { double vx,vy; assert (!active); if (!UtiliseMunition()) return false; // Ajoute la représentation uint x,y; if(Shoot==NULL) PosArmeXY (x,y); else { x=Shoot->getX(); y=Shoot->getY(); } baton.RAZ (); baton.PrepareTir(); baton.ChangeXY (x, y); lst_objets.AjouteObjet (&baton, true); // Ajoute la vitesse actuelle du ver VerActif().CalculeVitesse (vx, vy); baton.NouvelleForceXY (vx, vy); // Active l'animation active = true; jukebox.Play("weapon/dynamite_fuze"); if(Network&&Shoot==NULL) { connect()->envia(0,SHOOT,-1); connect()->envia(x,SHOOT,y); connect()->envia(0,SHOOT,0); } boucle_jeu.ChangeEtat (jeuVER_A_JOUE); return true; } For an "functional.." far from being playable, using a 0.4 code, just Ask I will send it. PS: I know, I know my english still need a lot of effort :( On Fri, 2004-11-05 at 00:29 +0100, Victor STINNER wrote: > Hi, > > I would like to know if you agree to make a new release (0.5beta3) which > include all bugfixes. > > And for network : some news from fact ? I would like to have your > opinion about how implementing the network. I proposed first to convert > keyboard and mouse event to "actions" which will be stored in a class > "WormuxActions". And, how would you support "security" (forbid tricks) ? > And, will the server be integrated *in* Wormux, or should it be an > external program. Don't forget : the simple programs are the best (it's > easier to debug small programs than very big ones). > > Bye, Haypo -- Filipe Teixeira <[EMAIL PROTECTED]>
#include <sys/types.h> #include <unistd.h> #include <stdio.h> #include <sys/errno.h> #include <string.h> #include <sys/ipc.h> #include <sys/msg.h> #include <stdlib.h> #include <ctype.h> #include <signal.h> #include <list> #include <ClanLib/core.h> #include <ClanLib/display.h> #include <ClanLib/network.h> #include <ClanLib/application.h> #include "../interface/keyboard.h" #include "../team/macro.h" #include "../game/game.h" #include "../game/game_loop.h" #include "../game/game_mode.h" #include "../team/move.h" #include "../team/teams_list.h" #include "../interface/cursor.h" #include "../team/character.h" #include "../team/team.h" #include "../game/config.h" #include <sstream> #include <dirent.h> #include <sys/stat.h> #include <algorithm> #define NETWORK_DEBUG 1 #define TRUE 1 #define FALSE 0 #define KEY 5550 #define PATH "maps/" network *connection; bool net; int team_identify; int your_team; using namespace std; std::vector<clientes*> cliente; int shoot::new_shoot(int param,int recurs,double params) { if(params!=1) { if(!l) { paramA=params; l++; } else { paramB=params; l--; i++; } return i; } if(recurs!=-1) { this->recurs=recurs; return 0; } switch(i) { case 0: force=param; break; case 1: x=param; break; case 2: y=param; break; case 3: angle=param; break; } i++; return i; } clientes::clientes(int ID) { this->ID=ID; equipe_actual=NULL; ver_actual=NULL; } uint y=0; int obtemX(int id_cliente) { std::vector<clientes*>::iterator i=cliente.begin(), t=cliente.end(); clientes *tmp=NULL; for(; i != t; ++i) if((&**i)->id()==id_cliente) { tmp=&**i; break; } if(tmp->equipe_actual==NULL) tmp->equipe_actual=gst_equipes.objectos(NULL); if(tmp->ver_actual==NULL) tmp->ver_actual=tmp->equipe_actual->objecto(NULL); else if((tmp->ver_actual=tmp->equipe_actual->objecto(tmp->ver_actual))==NULL) { std::cout << "muda de team"<<std::endl; tmp->equipe_actual=gst_equipes.objectos(tmp->equipe_actual); tmp->ver_actual=tmp->equipe_actual->objecto(NULL); } y=tmp->ver_actual->LitY(); return tmp->ver_actual->posX(); } int obtemY(int id_cliente) { return y; } int network::get_state() { return state; } network::network(char *port) { netgame = NULL; num_worms=12; Long=0; i=0; a=0; recebeu =0; try { netgame = new CL_NetSession("trans"); slot_connect = netgame->sig_computer_connected().connect(this, &network::on_server_connect); slot_disconnect = netgame->sig_computer_disconnected().connect(this, &network::on_server_disconnect); slot_receive_ping = netgame->sig_netpacket_receive("chat").connect(this, &network::on_chat_receive); slot_receive_message = netgame->sig_netpacket_receive("game").connect(this, &network::on_game_receive); slot_receive_string = netgame->sig_netpacket_receive("string").connect(this, &network::on_string_receive); std::cout << port<<"\n"; netgame->start_listen(port); } catch(CL_Error err) { std::cout << "Could not create server: " << err.message.c_str() << std::endl; std::cout << "We will try to be client instead." << std::endl; } try { std::cout << "*** server running ***" << std::endl; std::cout << "Start this program once more to start a client" << std::endl; CL_System::keep_alive(); } catch (CL_Error err) { std::cout << "Fatal server error: " << err.message.c_str() << std::endl; } } network::network() { return; } network::network(char * port, char *ip) { Long=0; num_worms=12; i=0;a=0; state=0; recebeu=0; netgame = NULL; try { netgame = new CL_NetSession("trans"); slot_disconnect = netgame->sig_computer_disconnected().connect(this, &network::on_client_disconnect); slot_receive_ping = netgame->sig_netpacket_receive("chat").connect(this, &network::on_chat_receive); slot_receive_message = netgame->sig_netpacket_receive("game").connect(this, &network::on_game_receive); slot_receive_string = netgame->sig_netpacket_receive("string").connect(this, &network::on_string_receive); CL_IPAddress server_ip; server_ip.set_address(ip, port); netgame->connect(server_ip); } catch(CL_Error err) { std::cout << "Could not create client: " << err.message.c_str() << std::endl; return; } try { std::cout << "*** client running ***" << std::endl; CL_System::keep_alive(); } catch (CL_Error err) { std::cout << "Fatal client error: " << err.message.c_str() << std::endl; } } void network::envia_string(int comando,std::string string) { CL_NetPacket msg; msg.output.write_int32(comando); msg.output.write_string(string); netgame->get_all().send("string", msg); std::cout << "Sent message" << std::endl; } void network::envia(int comando,int action,int aux,double a,double b) { CL_NetPacket *msg; msg=new CL_NetPacket(); msg->output.write_int16(action); msg->output.write_int16(comando); msg->output.write_int16(aux); netgame->get_all().send("game", *msg); if(action==LONG) { delete msg; msg=new CL_NetPacket(); msg->output.write_int16(comando); msg->output.write_float32(a); msg->output.write_float32(b); netgame->get_all().send("game", *msg); } std::cout << "Sent message" << std::endl; } void network::setTeam() { std::vector<Equipe*>::iterator it=gst_equipes.liste.begin(); int i=0; for(;client<i;++it,++i); your_team=&**it; } void network::on_server_connect(CL_NetComputer &computer) { int num; std::cout << "Client joined." << std::endl; std::vector<clientes*>::iterator i=cliente.end(); if(cliente.begin()==cliente.end()) num=0; else num=(&**i)->id(); clientes *tmp=new clientes(++num); cliente.push_back(tmp); envia(num,NEW_CLIENTE,0); } void network::on_server_disconnect(CL_NetComputer &computer) { std::cout << "Client disconnected." << std::endl; } void network::on_client_disconnect(CL_NetComputer &computer) { std::cout << "Lost connection to server." << std::endl; } void network::on_chat_receive(CL_NetPacket &packet, CL_NetComputer &computer) { return; } void network::on_string_receive(CL_NetPacket &packet, CL_NetComputer &computer) { int comando = packet.input.read_int32(); std::string string = packet.input.read_string(); if(comando==MAP_NAME) { } } void network::on_game_receive(CL_NetPacket &packet, CL_NetComputer &computer) { double paraA=-1,paraB=-1; int comando,tecla,aux; comando = packet.input.read_int16(); if(Long) { paraA = packet.input.read_float32(); paraB = packet.input.read_float32(); } else { tecla = packet.input.read_int16(); aux = packet.input.read_int16(); } int a,b; //changing weapon if(comando==NEW_GUN) EquipeActive().ChangeArme (static_cast<type_arme>(tecla)); //moving the guy if (comando==NEW_POSITION) { if (tecla == JUMP) VerActif().Saute(); if (tecla == SUPER_JUMP) VerActif().SuperSaut(); if (tecla == RIGHT) BougeVerDroite (VerActif()); if (tecla == LEFT) BougeVerGauche (VerActif()); } if(comando==NEW_GUY) { if(client) { guy[i].x=tecla; guy[i].y=aux; if((++i)==num_worms)recebeu=1; } else { while(i<num_worms) { a=obtemX(tecla); b=obtemY(tecla); std::cout<<a<<"-"<<b<<std::endl; envia(a,NEW_GUY,b); i++; } } } if(comando==NEW_CLIENTE)if(client)client=tecla; if(comando==SHOOT) switch(Shoot.new_shoot(tecla,-1,Long?paraA:-1)) { case 1: if(aux!=-1) Shoot.new_shoot(tecla,aux); break; case 2: Shoot.new_shoot(aux,-1,Long?paraB:-1); break; case 4: EquipeActive().AccesArme().Tire (&Shoot); Shoot.i=0; } if(comando==NEW_TEAM) { if(tecla==GIVE_UP) { jeu.autorise_action = false; boucle_jeu.ChangeEtat (jeuPAUSE_FIN_TOUR); curseur_ver.Cache(); } if(tecla==EXIT) { jeu.fin_partie = true; } if(tecla==PAUSEa) { jeu.Pause(); } } Long=0; if (comando==LONG) Long=1; } network *connect() { return connection; } int recebeu=0; int forks(char* porta,int is_creator, char *ip) { //trans=new transmition(KEY); CL_SetupNetwork::init(); if(is_creator) connection = new network(porta); else connection = new network(porta, ip); return 1; }
#include <ClanLib/network.h> #include <stdlib.h> #include "../team/character.h" #include "../object/physical_obj.h" #include "../game/config.h" #include <list> #define NEW_POSITION 0 #define NEW_GUN 1 #define NEW_SHOOT 2 #define RIGHT 0 #define LEFT 1 #define JUMP 2 #define SUPER_JUMP 3 #define NEW_SIGHT 3 #define NEW_TEAM 4 #define NEW_GUY 5 #define NEW_CLIENTE 6 #define SHOOT 7 #define LONG 8 #define GIVE_UP 0 #define EXIT 1 #define PAUSEa 2 #define MAP_NAME 0 class shoot { int force; int recurs; double paramA; double paramB; int x; int y; int angle; public: int i,l;//counters public: void setForce(int force){this->force=force;} void setX(int x){this->x=x;} void setR(int recurs){this->recurs=recurs;} void setY(int y){this->y=y;} void setAngle(int angle){this->angle=angle;} double getParamB(){return paramB;} double getParamA(){return paramA;} int getY(){return y;} int getR(){return recurs;} int getX(){return x;} int getAngle(){return angle;} int getForce(){return force;} int new_shoot(int param,int recurs=-1,double params=-1); }; class clientes { int ID; public: Equipe * equipe_actual; Ver * ver_actual; public: clientes(int ID); int id(){return ID;} }; class worm { public: uint x; uint y; }; struct network{ int state; int i,a; shoot Shoot; int num_worms; int Long; CL_Slot slot_connect; CL_Slot slot_disconnect; CL_Slot slot_receive_ping; CL_Slot slot_receive_message; CL_Slot slot_receive_string; worm guy[12]; Equipe* your_team; CL_NetSession *netgame; public: network(char *port); network(char *port,char * ip); network(); void setTeam(); Equipe *getTeam(){return your_team;} int download_file(); int upload_file(char *map); int get_state(); void on_server_connect(CL_NetComputer &computer); void on_server_disconnect(CL_NetComputer &computer); void on_client_disconnect(CL_NetComputer &computer); void on_game_receive(CL_NetPacket &packet, CL_NetComputer &computer); void on_chat_receive(CL_NetPacket &packet, CL_NetComputer &computer); void on_string_receive(CL_NetPacket &packet, CL_NetComputer &computer); void game(CL_NetPacket &packet, CL_NetComputer &computer); void envia(int comando,int action,int aux,double a=0,double b=0); void envia_string(int comando,std::string string); char * receive(int size); }; extern int recebeu; extern bool net; extern int team_identify; extern int client; extern network *connection; network *connect(); int forks(char* porta,int is_creator, char *ip); extern bool Network;