Пример #1
0
        /// 处理游戏服务器命令(返回二进制格式)
        private static bool ProcessGameStreamCmd(TCPClient client, int nID, byte[] data, int count)
        {
            byte[] bytesData = new byte[count];
            DataHelper.CopyBytes(bytesData, 0, data, 0, count);

            //通知外部
            client.NotifyRecvData(new SocketConnectEventArgs()
            {
                Error         = "Success",
                NetSocketType = (int)NetSocketTypes.SOCKT_CMD,
                CmdID         = (int)nID,
                fields        = null,
                bytesData     = bytesData,
            });
            return(true);
        }
Пример #2
0
        /// 处理游戏服务器命令
        private static bool ProcessGameCmd(TCPClient client, int nID, byte[] data, int count)
        {
            string strData = new UTF8Encoding().GetString(data, 0, count);

            //解析客户端的指令
            string[] fields = strData.Split(':');

            //通知外部
            client.NotifyRecvData(new SocketConnectEventArgs()
            {
                Error         = "Success",
                NetSocketType = (int)NetSocketTypes.SOCKT_CMD,
                CmdID         = (int)nID,
                fields        = fields
            });
            return(true);
        }
Пример #3
0
        /// 压入一个连接
        public void Push(TCPClient tcpClient)
        {
            //如果是已经无效的连接,则不再放入缓存池
            if (!tcpClient.IsConnected())
            {
                lock (this.pool)
                {
                    ErrCount++;
                }

                return;
            }

            lock (this.pool)
            {
                this.pool.Enqueue(tcpClient);
            }

            this.semaphoreClients.Release();
        }
Пример #4
0
        /// 处理与登陆服务服务器的网络协议命令
        public static bool ProcessServerCmd(TCPClient client, int nID, byte[] data, int count)
        {
            bool ret = false;

            switch (nID)
            {
            case (int)(TCPGameServerCmds.CMD_LOGIN_ON):
            case (int)(TCPGameServerCmds.CMD_ROLE_LIST):
            case (int)(TCPGameServerCmds.CMD_CREATE_ROLE):
            case (int)(TCPGameServerCmds.CMD_SYNC_TIME):
            case (int)(TCPGameServerCmds.CMD_PLAY_GAME):
            case (int)(TCPGameServerCmds.CMD_SPR_MOVEEND):
            case (int)(TCPGameServerCmds.CMD_SPR_POSITION):
            case (int)(TCPGameServerCmds.CMD_LOG_OUT):
            {
                ret = ProcessGameCmd(client, nID, data, count);
                break;
            }

            case (int)(TCPGameServerCmds.CMD_INIT_GAME):
            case (int)(TCPGameServerCmds.CMD_SPR_MOVE):
            case (int)(TCPGameServerCmds.CMD_SPR_ACTTION):
            case (int)(TCPGameServerCmds.CMD_SPR_INJURE):
            case (int)(TCPGameServerCmds.CMD_SPR_ATTACK):
            case (int)(TCPGameServerCmds.CMD_SPR_MAGICCODE):
            {
                ret = ProcessGameStreamCmd(client, nID, data, count);
                break;
            }

            default:
            {
                ret = true;
                break;
            }
            }

            return(ret);
        }
 void server_ClientConnected(TCPClient client)
 {
     UpdateServerListBox(client.RemoteAddress, "Connected");
 }
        void server_TextReceived(TCPClient remoteClient, string text)
        {
            // get the commands out of the string
            // 1 = who is it from
            // 2 = what does it want
            // 3 = who is it for

            string from    = GetTagToken(text, "1");
            string command = GetTagToken(text, "2");
            string forx    = "";
            string dowhat  = "";

            if (from.ToLower() == "client" && command.ToLower() == "command")
            {
                forx   = GetTagToken(text, "3");
                dowhat = GetTagToken(text, "4");
                if (forx.ToLower() == "drone" && droneConnected == true)
                {
                    drone.SendData(text);
                }
                UpdateServerListBox(remoteClient.RemoteAddress, "Client has sent the drone the following command " + dowhat);
            }
            else if (from.ToLower() == "drone" && command.ToLower() == "command")
            {
                forx   = GetTagToken(text, "3");
                dowhat = GetTagToken(text, "4");
                if (forx.ToLower() == "client" && clientConnected == true)
                {
                    client.SendData(text);
                }
                UpdateServerListBox(remoteClient.RemoteAddress, "Drone has sent the client the following command " + dowhat);
            }
            else if (from.ToLower() == "client" && command.ToLower() == "connected")
            {
                client          = remoteClient;
                clientConnected = true;
                UpdateServerListBox(remoteClient.RemoteAddress, "Client has connected");

                if (droneConnected == true) //tell the drone that the client has connected
                {
                    drone.SendData("1=server|2=clientisconnected|");
                    // and now tell the client that the drone is in fact connected
                    client.SendData("1=server|2=droneisconnected|");
                }
            }
            else if (from.ToLower() == "drone" && command.ToLower() == "connected")
            {
                drone          = remoteClient;
                droneConnected = true;
                UpdateServerListBox(remoteClient.RemoteAddress, "Drone has connected");
                if (clientConnected == true)
                {
                    client.SendData("1=server|2=droneisconnected|");
                    // and now tell the drone that the client is in fact connected
                    drone.SendData("1=server|2=clientisconnected|");
                }
            }
            else
            {
                UpdateServerListBox(remoteClient.RemoteAddress, text);
            }
        }