private void _run() { NetworkStream ns = (NetworkStream)this._protocol.receive(); Byte[] clientdata = new Byte[256]; ns.Read(clientdata, 0, 256); Protocol_handler ph = new Protocol_handler(); uint action = ph.getAction(clientdata); switch(action) { case (int)ServerProtocol.IDENTIFY_SEND : string pseudo; ph.Identify_receive(clientdata, out pseudo); lock (this._iptable) { Controller.get().AddPlayer(this._protocol, this._iptable, this._protocol.Ip(), (uint)PlayerSpecy.ZERG, pseudo); Monitor.PulseAll(this._iptable); } break; } //Controller.get().process(playerid, clientdata); }
/// <summary> /// Ajoute un nouveau joueur /// </summary> /// <param name="iptable">La table des IP</param> /// <param name="ip">L'adresse IP</param> /// <param name="idspecy">La race jouée</param> /// <param name="pseudo">Le pseudo du joueur</param> public void AddPlayer(IProtocolAdapter ipa, Dictionary<String, int> iptable, String ip, uint idspecy, string pseudo) { Specy sp; switch(idspecy){ case (uint)PlayerSpecy.ZERG : default : sp = new Specy("Zerg"); break; } iptable.Add(ip, Server.components.Game.getInstance().AddPlayer(sp, pseudo)); Protocol_handler ph = new Protocol_handler(); int width = Server.components.Game.getInstance().getMapWidth(); int height = Server.components.Game.getInstance().getMapHeight(); ipa.send(ph.Identify_mapSize(width, height)); }
private void _run() { Byte[] clientdata = (Byte[])this._protocol.receive(); lock (this._iptable) { while (this._iptable.Count() == 0) { Monitor.Wait(this._iptable); } } if (!this._iptable.ContainsKey(this._protocol.Ip())) { // Erreur Console.WriteLine("ERREUR"); } int playerid = this._iptable[this._protocol.Ip()]; Protocol_handler ph = new Protocol_handler(); uint action = ph.getAction(clientdata); uint target = 0, pos_x = 0, pos_y = 0; //use DoAction from 0 to 99 if (action < (uint)DoActionProtocol.END_SOURCEPOSITION) { if (action < (uint)DoActionProtocol.END_SOURCETARGET) { target = ph.getTarget(clientdata); } else { ph.getPosition(clientdata, out pos_x, out pos_y); } } switch(action) { case (int)ServerProtocol.UNIT_GETALL : Controller.get().sendAllUnits(this._protocol); break; case (int)ServerProtocol.UNIT_GETPOSITION : Controller.get().sendPosition(this._protocol, playerid, (int)ph.getSource(clientdata)); break; case (int)ServerProtocol.UNIT_MOVE : Controller.get().doAction((ushort)action, playerid, (int)ph.getSource(clientdata), (int)pos_x, (int)pos_y); break; case (int)ServerProtocol.UNIT_MUTATION: Controller.get().doAction((ushort)action, playerid, (int)ph.getSource(clientdata), ph.getEntityTarget(clientdata)); break; case (int)ServerProtocol.PLAYER_GETRESS : Controller.get().getInfoPlayer(this._protocol, playerid); break; case (int)ServerProtocol.UNIT_GETINFO : uint uid; ph.Entity_getInfo(clientdata, out uid); Controller.get().getInformationEntity(this._protocol, (int)uid); break; case (int)ServerProtocol.UNIT_ATTACK : case (int)ServerProtocol.UNIT_COLLECT : Controller.get().doAction((ushort)action, playerid, (int)ph.getSource(clientdata), (int)target); break; case (int)ServerProtocol.RESSOURCES_GETALL : Controller.get().sendAllResource(this._protocol); break; //case (int)ServerProtocol } //Controller.get().process(playerid, clientdata); }
/// <summary> /// Envoie la position /// </summary> /// <param name="ipa">L'adaptateur réseau</param> /// <param name="pid">Le numéro du joueur</param> /// <param name="srcid">Le numéro de l'entité source</param> public void sendPosition(IProtocolAdapter ipa, int pid, int srcid) { lock (this) { Protocol_handler ph = new Protocol_handler(); Point p = (Point)this.getPosition(pid, srcid); if (p == null) { throw new ConcreteEntitiesExistenceException(); } ipa.send(ph.Unit_position(srcid, p)); } }
/// <summary> /// Envoie la liste des unités /// </summary> /// <param name="ipa"></param> public void sendAllUnits(IProtocolAdapter ipa) { Protocol_handler ph = new Protocol_handler(); ipa.send(ph.Entity_sendlist(this.getAllUnits())); }
/// <summary> /// retourne les informations sur l'entité /// </summary> /// <param name="IdEntity"> identifiant de l'entité</param> /// <returns>informations sur l'entité</returns> public void getInformationEntity(IProtocolAdapter ipa, int IdEntity) { Protocol_handler ph = new Protocol_handler(); ipa.send(ph.Entity_sendinfo( Server.components.Game.getInstance().getInformationEntity(IdEntity) )); }
/// <summary> /// retourne les informations du player /// le vespen /// le mineraux /// popmax /// pop /// </summary> /// <param name="IdPlayer"> identifiant du player</param> public void getInfoPlayer(IProtocolAdapter ipa, int IdPlayer) { Protocol_handler ph = new Protocol_handler(); ipa.send(ph.Player_sendressources( Server.components.Game.getInstance().getInfoPlayer(IdPlayer) )); }