Exemplo n.º 1
0
        public void GetINFO(object O)
        {
            string     serverinfoStr;
            ServerInfo serverinfo = new ServerInfo();

            ServerConn[]  ServerArr = new ServerConn[OnlineServer.Count];
            object[]      vs        = (object[])O;
            ProtocolBytes bytes     = (ProtocolBytes)vs[0];
            TCP           conn      = (TCP)vs[1];
            int           i         = 0;

            foreach (ServerConn SC in OnlineServer)
            {
                ServerArr[i] = SC;
                i++;
            }
            for (int a = 0; a < ServerArr.Length - 1; a++)
            {
                for (int b = a + 1; b < ServerArr.Length; b++)
                {
                    if (ServerArr[a].UNitl > ServerArr[b].UNitl)
                    {
                        ServerConn Temp = ServerArr[a];
                        ServerArr[a] = ServerArr[b];
                        ServerArr[b] = Temp;
                    }
                }
            }
            if (ServerArr.Length == 0)
            {
                bytes.AddData(1);
                conn.Send(bytes);
                "MSG_Server: 没有启动".ColorWord(ConsoleColor.DarkRed);
                return;
            }
            bytes.AddData(0);
            serverinfo.IP           = ServerArr[0].IP;
            serverinfo.Port         = ServerArr[0].Port;
            serverinfo.ServerVrsion = ServerArr[0].Server_Vrsion;
            serverinfoStr           = JsonConvert.SerializeObject(serverinfo);

            Console.WriteLine("ToClient " + serverinfo.IP + " " + serverinfo.Port.ToString());
            bytes.AddData(serverinfoStr);
            bytes.AddData(conn.Player.ReConnectCheckCode);
            conn.Send(bytes);
        }
Exemplo n.º 2
0
        private void HandleMsg(TCP conn, ProtocolBase protoBase)
        {
            ProtocolBytes bytes = (ProtocolBytes)protoBase;
            // Console.WriteLine("收到" + bytes.ProtocolName().ToString());
            string name  = bytes.Protocol.ToString();
            int    index = name.LastIndexOf("_");

            name = name.Substring(index + 1);
            object[] OB = bytes.GetDecode();
            string   s  = "";

            for (int i = 0; i < bytes.GetDecode().Length; i++)
            {
                s += bytes.GetDecode()[i].ToString();
            }
            //if (s != "HearBeat")
            Console.WriteLine(name + " " + s);
            string methodname = name;

            if (ProtocolSort.FriendProtocol.Contains(bytes.Protocol))
            {
                MethodInfo mm  = HandFriendEventMP.GetType().GetMethod(methodname);
                object[]   obj = new object[] { conn, OB };
                mm.Invoke(HandFriendEventMP, obj);
            }
            else if (bytes.Protocol == Fursion_Protocol.LockStep)
            {
                try
                {
                    MethodInfo mm  = handFPSMsg.GetType().GetMethod(methodname);
                    object[]   obj = new object[] { protoBase };
                    mm.Invoke(handFPSMsg, obj);
                }
                catch (Exception e)
                { Console.WriteLine(e.Message + " 221"); }
            }
            else if (ProtocolSort.MSGProtocol.Contains(bytes.Protocol))
            {
                try
                {
                    MethodInfo mm = handleConnMP.GetType().GetMethod(methodname);
                    if (mm == null)
                    {
                        string str = "[Warning]HandleMsg Don't Have method precessing method in HandleConnMethodPool" + bytes.Protocol;
                        Console.WriteLine(str + methodname);
                    }
                    object[] obj = new object[] { protoBase };
                    mm.Invoke(handleConnMP, obj);
                }
                catch (Exception e)
                { Console.WriteLine(e.Message + "  239"); }
            }
            else if (conn.Player == null || ProtocolSort.ConnectProtocol.Contains(bytes.Protocol) || name == "JSONTEST")
            {
                try
                {
                    MethodInfo mm = handleConnMP.GetType().GetMethod(methodname);
                    if (mm == null)
                    {
                        string str = "【warning】 handlemsg没有处理连接方法";
                        Console.WriteLine(str + methodname);
                        if (conn.Player == null)
                        {
                            ProtocolBytes RestConnect = new ProtocolBytes();
                            RestConnect.SetProtocol(Fursion_Protocol.Reconnect);
                            conn.Send(RestConnect);
                        }
                    }
                    object[] obj = new object[] { conn, protoBase };
                    try
                    {
                        mm.Invoke(handleConnMP, obj);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message + "256");
                    }
                }
                catch (Exception e)
                { Console.WriteLine(e.Message + "  261"); }
            }
            else if (ProtocolSort.TeamProtocol.Contains(bytes.Protocol))
            {
                try
                {
                    MethodInfo mm = HandTeameEventMP.GetType().GetMethod(methodname);
                    if (mm == null)
                    {
                        string str = "【warning】 Don't Method precessing in HandTeameEventMP";
                        Console.WriteLine(str + methodname);
                    }
                    object[] obj = new object[] { conn, protoBase };
                    try
                    {
                        mm.Invoke(HandTeameEventMP, obj);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message + "256");
                    }
                }
                catch (Exception e)
                { Console.WriteLine(e.Message + "  261"); }
            }
            else if (ProtocolSort.LockStepProtocol.Contains(bytes.Protocol))
            {
            }
            else
            {
                try
                {
                    MethodInfo mm = handlePlayerEvent.GetType().GetMethod(methodname);
                    if (mm == null)
                    {
                        if (conn.Player == null)
                        {
                            ProtocolBytes RestConnect = new ProtocolBytes();
                            RestConnect.SetProtocol(Fursion_Protocol.Reconnect);
                            conn.Send(RestConnect);
                        }
                        string str = "[警告]handlemsg没有处理玩家方法";
                        Console.WriteLine(str + methodname);
                    }
                    object[] obj = new object[] { conn, protoBase };
                    Console.WriteLine("[处理玩家消息]" + conn.GetAddress() + name);
                    mm.Invoke(handlePlayerEvent, obj);
                }
                catch (Exception e)
                { Console.WriteLine(e.Message + "  247"); }
            }
        }