public void NextTurn()
    {
        StopClock();
        _isBreak = true;
        playerBlue.Stop();
        playerRed.Stop();

        if (GameObject.ReferenceEquals(_currentPlayer, playerBlue))
        {
            _currentPlayer = playerRed;
            blueTankTurnIcon.gameObject.SetActive(false);
            redTankTurnIcon.gameObject.SetActive(true);
        }
        else
        {
            _currentPlayer = playerBlue;
            blueTankTurnIcon.gameObject.SetActive(true);
            redTankTurnIcon.gameObject.SetActive(false);
        };

        playerBlue.Stop();
        playerRed.Stop();

        CLog.Info($"New Turn: {_currentPlayer.gameObject.name}");
        StartCoroutine(startTurnAfterSeconds(2));
    }
Exemple #2
0
	public void SV_ExecuteClientMessage(ClientNode cl, MsgPacket msg)
	{
		
		msg.Oob = false;
		int srvID = msg.ReadInt();
		cl.messageAcknowledge = msg.ReadInt();
		if(cl.messageAcknowledge < 0){
			DropClient(cl,"illegible client message");
			return;
		}

		cl.reliableAcknowledge = msg.ReadInt();
		if(cl.reliableAcknowledge < cl.reliableSequence - CConstVar.MAX_RELIABLE_COMMANDS){
			DropClient(cl,"illegible client message");
			cl.reliableAcknowledge = cl.reliableSequence;
			return;
		}

		if(srvID != serverID ){
		// 	if(serverID >= restartedServerId && srvID < serverID){
		// 		CLog.Info("{0} : ignoring pre map_restart/ outdated client message",cl.name);
				
				if(cl.messageAcknowledge > cl.gamestateMessageNum){
					SendClientGameState(cl);
				}
				return;
		}
		// }

		if(cl.oldServerTime > 0 && srvID == serverID){
			CLog.Info("{0} ackownledged gamestate", cl.name);
			cl.oldServerTime = 0;
		}

		int c = 0;
		do{
			c = msg.ReadByte();
			if(c == (int)CLC_Cmd.EOF){
				break;
			}
			if(c != (int)CLC_Cmd.ClientCommand){
				break;
			}
			if(!ClientCommand(cl, msg)){
				return;
			}
			if(cl.state == ClientState.ZOMBIE){
				return;
			}
		}while(true);


		if(c == (int)CLC_Cmd.MOVE){
			UserMove(cl,msg, true);
		}else if(c == (int)CLC_Cmd.MoveNoDelta){
			UserMove(cl,msg,false);
		}else if(c != (int)CLC_Cmd.EOF){
			CLog.Info("bad command type for client!!!!");
		}
	}
Exemple #3
0
    //network层已经做了fragment的拆分处理
    public void SendMsg(byte[] bytes, int length, IPEndPoint to)
    {
        if (CConstVar.ShowNet > 0)
        {
            CLog.Info("send msg, length {0}, to {1}", length, to);
        }
        if (to.Address == IPAddress.Broadcast)         //直接发送数据
        //Array.Copy(bytes,0,sendBuffer,0,length);
        {
            sendSocket.BeginSendTo(bytes, 0, length, SocketFlags.None, to, SendCallback, sendSocket);
        }
        else           //这里也不需要进行处理
                       // sendSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName)
                       // sendBuffer[0] = 0;
                       // sendBuffer[1] = 0;
                       // sendBuffer[2] = 0;
                       // sendBuffer[3] = 1; //IP

        // Array.Copy(to.Address.GetAddressBytes(),0,sendBuffer,4, 4);
        // sendBuffer[8] = (byte)(CConstVar.Qport >> 8); //发送的是自己监听的端口
        // sendBuffer[9] = (byte)(CConstVar.LocalPort);
        // Array.Copy(bytes,0,sendBuffer, 10, length); //前10个字节是保留的
        // Array.Copy(bytes, sendBuffer, length);
        // sendSocket.BeginSendTo(sendBuffer, 0, length + 10, SocketFlags.None, to, SendCallback, sendSocket);
        {
            sendSocket.BeginSendTo(bytes, 0, length, SocketFlags.None, to, SendCallback, sendSocket);
        }
    }
Exemple #4
0
	private void CheckTimeouts(){
		int droppoint = time - 1000 * CConstVar.SV_TimeOut;
		int zombiepoint = time - 1000 * CConstVar.SV_ZombieTime;

		for(int i = 0; i < CConstVar.MAX_CLIENTS; i++){
			var cl = clients[i];
			//在切换关卡的时候message time可能错乱
			if(cl.lastPacketTime > time){
				cl.lastPacketTime = time;
			}

			if(cl.state == ClientState.ZOMBIE && cl.lastPacketTime < zombiepoint){
				// cl.state = ClientState.FREE;
				cl.Clear();
				CLog.Info("Going from zombie to free for client {0}", i);
				continue;
			}

			if(cl.state >= ClientState.CONNECTED && cl.lastPacketTime < droppoint){
				//等待几帧再断开,防止调试出现的等待
				if(++cl.timeoutCount > 5){
					DropClient(cl, "time out");
					// cl.state = ClientState.FREE;
				}
			}else{
				cl.timeoutCount = 0;
			}
		}
	}
Exemple #5
0
    public void DestroyParticle(int particleID, bool immediately)
    {
        bool hasParticle = false;
        int  count       = particlesList.Count;

        for (int i = count - 1; i >= 0; i--)
        {
            ParticleItem item = particlesList[i];
            if (item.particleID == particleID)
            {
                if (immediately)
                {
                    particlesList.Remove(item);
                }
                else
                {
                    item.toBeRemoved = true;
                }
                hasParticle = true;
            }
        }

        if (!hasParticle)
        {
            CLog.Info("Particle is not in the list");
        }
    }
Exemple #6
0
    //处理广播消息等。
    //第一个字节用来区分game channel的消息(-1表示connectionless数据,1表示有数据)
    //而在c#中并没有暴露底层的接口来支持显式发送oob,所以用第一位来表示是否是带外数据
    protected void ConnectionlessPacket(IPEndPoint from, MsgPacket msg)
    {
        msg.BeginReadOOB();
        msg.ReadInt();         //skip -1 //跳过前面的-1
        string s   = msg.ReadStringLine();
        var    cmd = CDataModel.CmdBuffer;

        cmd.TokenizeString(s, false);
        string c = cmd.Argv(0);

        CLog.Info("Client Packet {0} : {1}", from, c);

        if (c == "challengeResponse")
        {
            CDataModel.Connection.PacketChallengeResponse(from, msg);
            return;
        }

        //服务器连接
        if (c == "connectResponse")
        {
            CDataModel.Connection.PacketConnectResponse(from, msg);
            return;
        }

        //服务器返回信息
        if (c == "infoResponse")
        {
            CDataModel.GameState.ServerInfoPacket(from, msg);
            return;
        }

        if (c == "statusResponse")
        {
            CDataModel.GameState.ServerStatusResponse(from, msg);
            return;
        }

        if (c == "echo")
        {
            return;
        }

        if (c == "keyAuthorize")
        {
            return;
        }

        if (c == "getserversResponse")
        {
            CDataModel.GameState.ServerResponsePacket(from, msg, false);
            return;
        }

        if (c == "getserversExtResponse")
        {
            CDataModel.GameState.ServerResponsePacket(from, msg, true);
            return;
        }
    }
 public void StartClock(int seconds)
 {
     clock = seconds;
     CLog.Info("Clock starts");
     _clockIsRunning = true;
     StartCoroutine(countTime());
 }
Exemple #8
0
	private void SendClientSnapshot(ClientNode client){
		byte[] msg_buf = new byte[CConstVar.MAX_MSG_LEN];

		//构建snapshot
		BuildClientSnapshot(client);

		//机器人有自己的构建方法,不需要发送
		if(client.gEntity != null && (client.gEntity.r.svFlags & SVFlags.BOT) != SVFlags.NONE){
			return;
		}


		//这里要默认开始压缩
		MsgPacket msg = new MsgPacket();
		msg.Oob = false;
		msg.AllowOverflow = true;

		//让客户端知道服务器已经收到的可靠消息。
		msg.WriteInt(client.lastClientCommand);

		//发送任何可靠的服务器指令
		UpdateServerCommandsToClient(client, msg);

		//发送所有的相应的entityState和playerState
		WriteSnapshotToClient(client, msg);

		if(msg.Overflowed){
			CLog.Info("WARNING: msg overflowed for %s", client.name);
			msg.Clear();
		}

		SendMessageToClient(msg, client);
	}
Exemple #9
0
 private void MoveGun(float axisRatio)
 {
     if (IsMyTurn != true)
     {
         return;
     }
     CLog.Info($"Moving Gun with {axisRatio.ToString()} ratio");
     gun.RotateGun(axisRatio);
 }
Exemple #10
0
 private void Move(float axisRatio)
 {
     if (IsMyTurn != true)
     {
         return;
     }
     CLog.Info($"Moving with {axisRatio.ToString()} ratio");
     tank.Move(axisRatio);
 }
Exemple #11
0
 public MainWindow()
 {
     InitializeComponent();
     this.Closed += MainWindow_Closed;
     CLog.Info("Info");
     CLog.Warning(0, "Warning");
     CLog.Error(1, "Error");
     this.Content = CLog.Instance;
 }
Exemple #12
0
    public void PacketConnectResponse(IPEndPoint from, MsgPacket msg)
    {
        int chNum;

        if (state >= ConnectionState.CONNECTED)
        {
            CLog.Info("Dup connect recieved. Ignored.");
            return;
        }

        // if(state != ConnectionState.CHALLENGING)
        // {
        //  CLog.Info("connectResponse packet while not connecting. Ignored.");
        //  return;
        // }
        string p       = CDataModel.CmdBuffer.Argv(2);
        int    tmpPort = from.Port;

        if (!string.IsNullOrEmpty(p))
        {
            from.Port = System.Convert.ToInt32(p);
        }

        if (!from.Equals(serverAddress))
        {
            CLog.Info("connectResponse from wrong address. Ignored.");
            return;
        }

        string c = CDataModel.CmdBuffer.Argv(1);

        if (!string.IsNullOrEmpty(c))
        {
            chNum = Convert.ToInt32(c);
        }
        else
        {
            CLog.Info("Bad connectResponse recieved. Ignored.");
            return;
        }
        if (chNum != challenge)
        {
            CLog.Info("ConnectionResponse with bad challenge received. Ignored.");
            return;
        }

        string id  = CDataModel.CmdBuffer.Argv(3);
        var    cla = CDataModel.GameState.ClActive;

        // if(!string.IsNullOrEmpty(id)){
        //  cla.serverID = Convert.ToInt32(id);
        // }

        NetChanSetup(NetSrc.CLIENT, from, tmpPort, challenge);
        state = ConnectionState.CONNECTED;
        lastPacketSentTime = -9999;         //立即发送第一个数据包
    }
Exemple #13
0
 public void AddThinkerModifier(BaseModifier modifier)
 {
     if (!updateModifiers.Contains(modifier))
     {
         updateModifiers.Add(modifier);
     }
     else
     {
         CLog.Info("There is a same thinker modifier: %s", modifier.ToString());
     }
 }
Exemple #14
0
 public void UnRegisterModifier(BaseModifier modifier)
 {
     if (updateModifiers.Contains(modifier))
     {
         updateModifiers.Add(modifier);
     }
     else
     {
         CLog.Info("There is not the thinker modifier: %s", modifier.ToString());
     }
 }
Exemple #15
0
    /*----------- lua调用C#的接口 ----------*/
    public Component getComponent(string objPath, string typeName)
    {
        var trans = transform.Find(objPath);

        if (trans == null)
        {
            CLog.Info("transform is null");
            return(null);
        }
        return(trans.GetComponent(typeName));
    }
Exemple #16
0
 public static void Prefix(ExileController __instance)
 {
     if (__instance.exiled != null)
     {
         if (Helper.isJester(__instance.exiled.PlayerId))
         {
             CLog.Info("Jester Voted Out");
             __instance.completeString = __instance.exiled.PlayerName + " was the Jester";
             ShipStatus.RpcEndGame(GameOverReason.HumansByVote, false);
         }
     }
 }
Exemple #17
0
    /* ----------------UDP START--------------------- */

    public void PacketEvent(MsgPacket packet, IPEndPoint from)
    {
        var connection = CDataModel.Connection;

        // if(Server.Instance.ServerRunning){
        //  Server.Instance.SV_PacketPrcess(packet, from);
        // }else{

        connection.lastPacketTime = CDataModel.GameState.realTime;
        if (packet.CurSize >= 4 && packet.ReadFirstInt() == -1)
        {
            ConnectionlessPacket(from, packet);
            return;
        }
        if (connection.state < ConnectionState.CONNECTED)
        {
            return;
        }
        if (packet.CurSize < 4)
        {
            CLog.Info("{0}: wrong packet", from.Address);
            return;
        }

        var netChan = CDataModel.Connection.NetChan;

        if (!from.Address.Equals(connection.NetChan.remoteAddress.Address) || from.Port != netChan.qport)
        {
            CLog.Info("{0}: sequenced packet without connection", from);
            return;
        }

        if (!NetChanProcess(ref netChan, packet))
        {
            return;
        }

        //可靠消息和不可靠消息的头是不同的
        int headerBytes = packet.CurPos;

        //记录最后接收到的消息,这样它可以在客户端信息中返回,允许服务器检测丢失的gamestate
        connection.serverMessageSequence = packet.ReadFirstInt();
        connection.lastPacketTime        = CDataModel.GameState.time;

        ParseMessage(packet);

        //在解析完packet之后,不知道是否能保存demo message
        if (connection.demoRecording && !connection.demoWaiting)
        {
            WriteDemoMessage(packet, headerBytes);
        }
        // }
    }
Exemple #18
0
        private TransResult Unpack8583()
        {
            var ret = TransResult.E_RECV_FAIL;

            try
            {
                var RecvData = new byte[recvLen - headLen];
                RecvData = UnpackHead();

                byte[] len8583 = new byte[2];
                Array.Copy(RecvData, len8583, 2);
                int lenthOf8583 = len8583[0] * 256 + len8583[1];
                if (lenthOf8583 != 0)
                {
                    var RecvBytes = new byte[RecvData.Length - headLen_8583]; //包体数据
                    Array.Copy(RecvData, headLen_8583, RecvBytes, 0, RecvData.Length - headLen_8583);
                    var headBytes = new byte[headLen_8583];
                    Array.Copy(RecvData, headBytes, headLen_8583); //包头数据
                    //解包
                    ret        = TransResult.E_UNPACKET_FAIL;
                    FrontBytes = headBytes;
                    HandleFrontBytes(headBytes); //根据报文头来判断是否要下载密钥
                    RecvPackage.ParseBuffer(RecvBytes, SendPackage.ExistValue(0));


                    var nRet = UnPackFix();
                    if (!mInvokeSetResult)
                    {
                        throw new Exception("should invoke SetRespInfo() in UnPackFix()");
                    }
                    mInvokeSetResult = false;
                    ret = nRet ? TransResult.E_SUCC : TransResult.E_HOST_FAIL;
                    CLog.Info(RecvPackage.GetLogText());
                }
                else
                {
                    ret = TransResult.E_HOST_FAIL;
                }
                if (recvLen > headLen + lenthOf8583 + 2)
                {
                    byte[] jsonByte = new byte[recvLen - headLen - lenthOf8583 - 2];
                    Array.Copy(RecvData, lenthOf8583 + 2, jsonByte, 0, jsonByte.Length);
                    var strJson = Encoding.Default.GetString(jsonByte);
                    RecvPackageJson = JsonConvert.DeserializeObject <CommunicateInfo>(strJson);
                }
            }
            catch (Exception ex)
            {
                Log.Error(GetType().Name, ex);
            }
            return(ret);
        }
Exemple #19
0
    private void SendCallback(IAsyncResult ar)
    {
        int count = sendSocket.EndSendTo(ar);

        if (count > 0)
        {
            CLog.Info("Send Packet Finish. length: {0}, rmeote addr:{1}", count, recvSocket.RemoteEndPoint);
        }
        else
        {
            CLog.Info("send zero bytes");
        }
    }
Exemple #20
0
    public void NetChanTransmitNextFrame(ref NetChan netChan)
    {
        MsgPacket send = new MsgPacket();

        send.Oob = true;
        byte[] send_buf         = new byte[CConstVar.PACKET_MAX_LEN];
        int    fragmentLength   = 0;
        int    outgoingSequence = netChan.outgoingSequence | CConstVar.FRAGMENT_BIT;

        send.WriteInt(outgoingSequence);

        //如果是客户端就发送qport
        if (netChan.src == NetSrc.CLIENT)
        {
            send.WriteInt(CConstVar.Qport);
        }

        send.WriteInt(CheckSum(netChan.challenge, netChan.outgoingSequence));

        fragmentLength = CConstVar.FRAGMENT_SIZE;
        if (netChan.unsentFragmentStart + fragmentLength > netChan.unsentLength)
        {
            fragmentLength = netChan.unsentLength - netChan.unsentFragmentStart;
        }

        send.WriteShort((short)netChan.unsentFragmentStart);
        send.WriteShort((short)fragmentLength);
        send.WriteBufferData(netChan.unsentBuffer, -1, fragmentLength, netChan.unsentFragmentStart);

        //发送数据
        SendPacket(netChan.src, send.CurSize, send.Data, netChan.remoteAddress);

        //存储发送的时间和大小
        netChan.lastSentTime = CDataModel.InputEvent.Milliseconds();
        netChan.lastSentSize = send.CurSize;

        if (CConstVar.ShowPacket > 0)
        {
            CLog.Info("%s send %d : s=%d fragment=%d,%d", netChan.src, send.CurSize, netChan.outgoingSequence, netChan.unsentFragmentStart, fragmentLength);
        }

        netChan.unsentFragmentStart += fragmentLength;

        //现在的情况有点戏剧,因为一个packet如果刚好是fragment的长度
        //那还需要发送第二个packet(长度为0),这样另外一端就知道是否有更多的packet。
        if (netChan.unsentFragmentStart == netChan.unsentLength && CConstVar.FRAGMENT_SIZE != fragmentLength)
        {
            netChan.outgoingSequence++;
            netChan.unsentFragments = false;
        }
    }
Exemple #21
0
    //发送的data数据是压缩过的,所以这里oob是true,不进行压缩
    public void NetChanTransmit(ref NetChan netChan, int length, byte[] data)
    {
        MsgPacket send = new MsgPacket();

        byte[] sendBuf = new byte[CConstVar.PACKET_MAX_LEN];
        if (length > CConstVar.PACKET_MAX_LEN)
        {
            CLog.Info("Netchan transmit overflow, length = {0}", length);
        }
        netChan.unsentFragmentStart = 0;

        //fragment large reliable messages
        if (length >= CConstVar.FRAGMENT_SIZE)
        {
            netChan.unsentFragments = true;
            netChan.unsentLength    = length;
            Array.Copy(data, 0, netChan.unsentBuffer, 0, length);

            //只发送第一帧的数据
            NetChanTransmitNextFrame(ref netChan);
        }

        send.Oob = true;
        //写入packet header
        send.WriteInt(netChan.outgoingSequence);

        //发送qport
        if (netChan.src == NetSrc.CLIENT)            //客户端发送到服务器需要qport
        {
            send.WriteShort((short)CConstVar.Qport); //这里qport跟本地监听端口一致
        }

        send.WriteInt(CheckSum(netChan.challenge, netChan.outgoingSequence));         //checksum
        netChan.outgoingSequence++;

        send.WriteData(data, length);         //data的数据写入到packet中

        //发送数据
        SendPacket(netChan.src, send.CurSize, send.Data, netChan.remoteAddress);

        //存储这个包发送的时间和大小。
        netChan.lastSentTime = CDataModel.InputEvent.Milliseconds();
        netChan.lastSentSize = send.CurSize;

        if (CConstVar.ShowPacket > 0)
        {
            CLog.Info("{0} send {1} : outgoSeq = {2} incomSeq = {3}", netChan.src, send.CurSize, netChan.outgoingSequence - 1, netChan.incomingSequence);
        }
    }
Exemple #22
0
 public void RegisterEvent(AbilityEventType eType, BaseAction action)
 {
     if (!eventActions.ContainsKey(eType))
     {
         eventActions.Add(eType, new List <BaseAction>());
     }
     if (!eventActions[eType].Contains(action))
     {
         eventActions[eType].Add(action);
     }
     else
     {
         CLog.Info("There is same action with the event type: %s", action.ToString());
     }
 }
Exemple #23
0
    public bool GetSnapshot(int snapshotNum, SnapShot snapshot)
    {
        ClientSnapshot clSnapshot;
        int            i, count;

        if (snapshotNum > clientActive.snap.messageNum)
        {
            CLog.Error("GetSnapshot: snapshotNum > gamestate.snap.messageNum");
        }

        if (clientActive.snap.messageNum - snapshotNum >= CConstVar.PACKET_BACKUP)
        {
            return(false);
        }

        clSnapshot = clientActive.snapshots[snapshotNum & CConstVar.PACKET_MASK];
        if (!clSnapshot.valid)
        {
            return(false);
        }

        //如果当前帧的entities超出了环形缓冲,我们不能返回它
        if (clientActive.parseEntitiesIndex - clSnapshot.parseEntitiesIndex >= CConstVar.MAX_PARSE_ENTITIES)
        {
            return(false);
        }

        //写入snapshot
        snapshot.snapFlags             = clSnapshot.snapFlags;
        snapshot.serverCommandSequence = clSnapshot.serverCommandNum;
        snapshot.ping        = clSnapshot.ping;
        snapshot.serverTime  = clSnapshot.serverTime;
        snapshot.playerState = clSnapshot.playerState;
        count = clSnapshot.numEntities;
        if (count > CConstVar.MAX_ENTITIES_IN_SNAPSHOT)
        {
            CLog.Info("GetSnapshot: truncated %d entities to %d", count, CConstVar.MAX_ENTITIES_IN_SNAPSHOT);
            count = CConstVar.MAX_ENTITIES_IN_SNAPSHOT;
        }

        snapshot.numEntities = count;
        for (i = 0; i < count; i++)
        {
            snapshot.entities[i] = clientActive.parseEntities[(clSnapshot.parseEntitiesIndex + i) & (CConstVar.MAX_PARSE_ENTITIES - 1)];
        }

        return(true);
    }
Exemple #24
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        Player player = other.GetComponentInParent <Player>();

        if (player != null)
        {
            CLog.Info("Hit Player!");
            missileAnimatior.SetTrigger("MissileHit");
            player.Health -= 1;
        }
        else
        {
            CLog.Info($"Missed! Hitted {other.name}");
            missileAnimatior.SetTrigger("MissileMiss");
        }
        missileRigidbody.Sleep();
    }
Exemple #25
0
    private void Fire(double fireTime)
    {
        if (IsMyTurn != true)
        {
            return;
        }

        if (fireTime == .0f)
        {
            CLog.Info($"Loading gun");
            gun.Load();
            return;
        }

        CLog.Info($"Fired after loading {fireTime.ToString()}s");
        gun.Fire((float)fireTime);
        GameMaster.instance.NextTurn();
    }
Exemple #26
0
    public void ChangeTrackingProjectileSpeed(BaseAbility ability, int speed)
    {
        bool hasAbility = false;
        int  count      = projectiles.Count;

        for (int i = 0; i < count; i++)
        {
            if (projectiles[i].Ability == ability)
            {
                projectiles[i].MoveSpeed = speed;
                hasAbility = true;
            }
        }
        if (!hasAbility)
        {
            CLog.Info("there is not a projectile associated with the ability");
        }
    }
    private GameEntity Spawn()
    {
        GameEntity e = null;
        int        i = 0;

        for (int force = 0; force < 2; force++)
        {
            e = gEntities[CConstVar.MAX_CLIENTS];
            //遍历所有的entity,但是找不到一个可用的
            for (i = CConstVar.MAX_CLIENTS; i < numEntities; i++)
            {
                e = gEntities[CConstVar.MAX_CLIENTS + i];
                if (e.inuse)
                {
                    continue;
                }

                if (force == 0 && (e.freeTime > startTime + 2000) && (time - e.freeTime < 1000))
                {
                    continue;
                }

                InitGEntity(e);
                return(e);
            }
            if (i != CConstVar.MAX_GENTITIES)
            {
                break;
            }
        }
        if (i == CConstVar.ENTITYNUM_MAX_NORMAL)
        {
            for (i = 0; i < CConstVar.MAX_GENTITIES; i++)
            {
                CLog.Info("gEntity name: {0}", gEntities[i].classname);
            }
            CLog.Error("Spawn: no free entities");
        }
        numEntities++;
        Server.Instance.SetGEntsNum(numEntities);

        InitGEntity(e);
        return(e);
    }
Exemple #28
0
    public void PacketChallengeResponse(IPEndPoint from, MsgPacket msg)
    {
        if (CDataModel.Connection.state == ConnectionState.CONNECTING)
        {
            CLog.Info("Unwanted challenge response recieved. Ignored.");
            return;
        }

        // int ch = 0;
        // int ver = 0;
        var cmd      = CDataModel.CmdBuffer;
        var userinfo = cmd.Argv(2);
        var port     = CUtils.GetValueForKey(userinfo, "port");

        if (!string.IsNullOrEmpty(port))
        {
            netChan.qport = from.Port = System.Convert.ToInt32(port);
        }
        // string c = cmd.Argv(1);
        // if(!string.IsNullOrEmpty(c))
        // {
        //  ch = Convert.ToInt32(c);
        // }
        // string sver = cmd.Argv(3);
        // if(!string.IsNullOrEmpty(sver)){
        //  ver = Convert.ToInt32(sver);
        // }

        // if(string.IsNullOrEmpty(c) || ch != challenge)
        // {
        //  CLog.Info("Bad challenge for challengeResponse. Ignored.");
        //  return;
        // }

        //发送challenge response,而不是challenge request packets
        challenge          = Convert.ToInt32(cmd.Argv(1));
        netChan.challenge  = challenge;
        state              = ConnectionState.CHALLENGING;
        connectPacketCount = 0;
        connectTime        = -99999;

        //使用这个地址作为新的服务器地址。这允许服务器代理处理到多个服务器的连接
        serverAddress = from;
    }
Exemple #29
0
	public void SV_ConnectionlessPacket(IPEndPoint from, MsgPacket packet)
	{
		packet.BeginReadOOB();
		packet.ReadInt(); //skip -1 marker

		// if(packet.ReadChars(7, 4) == "connect")
		// {
		// 	HuffmanMsg.Decompress(packet, 12);
		// }

		string s = packet.ReadStringLine();
		var cmd = CDataModel.CmdBuffer;
		cmd.TokenizeString(s, false);

		string c = cmd.Argv(0);
		CLog.Info("SV received packet {0} : {1}", from, c);
		int cport = 0;
		switch(c)
		{
			case "getstatus":
				SVCStatus(from);
				break;
			case "getinfo": //带上客户端的端口号
				cport = Convert.ToInt32(cmd.Argv(2));
				if(cport > 0) from.Port = cport;
				SVCInfo(from);
				break;
			case "getchallenge":
				SVCGetChallenge(from);
				break;
			case "connect":
				DirectConnect(from);
				break;
			case "rcon":
				RemoteCommand(from, packet);
				break;
			case "disconnect":
				break;
			default:
				CLog.Info("bad connectionless packet from {0}: {1}", from, s);
				break;
		}
	}
Exemple #30
0
    private SnapShot ReadNextSnapshot()
    {
        bool     r;
        SnapShot dest;

        if (latestSnapshotNum > processedSnapshotNum + 1000)
        {
            CLog.Info("ReadNextSnapshot: way out of range. %d > %d", latestSnapshotNum, processedSnapshotNum);
        }

        while (processedSnapshotNum < latestSnapshotNum)
        {
            if (snap == activeSnapshots[0])
            {
                dest = activeSnapshots[1];
            }
            else
            {
                dest = activeSnapshots[0];
            }

            processedSnapshotNum++;
            // dest = new SnapShot();
            r = GetSnapshot(processedSnapshotNum, dest);

            if (snap != null && r && dest.serverTime == snap.serverTime)
            {
            }

            //如果成功,就返回
            if (r)
            {
                AddLagometerSnapshotInfo(dest);
                return(dest);
            }

            //
            AddLagometerSnapshotInfo(null);
        }

        return(null);
    }