Example #1
0
 public void RecvData()
 {
     RecvParams = RecvString.Split('\n');
     if (!IsMatched)
     {
         ServerResult ret;
         if (IsMatchVersion)
         {
             if (RecvParams.Length == 3)
             {
                 if (RecvParams[0] == "reg")
                 {
                     ret = Program.RegDevice(RecvParams[1], RecvParams[2]);
                     if (ret.IsSuccess)
                     {
                         IsMatched = true;
                         UsedKey   = RecvParams[1];
                         NickName  = Program.key_nick.GetFirstYWithX(UsedKey, GetMD5(UsedKey));
                     }
                     Send(ret.Value());
                     return;
                 }
                 else
                 {
                     return;
                 }
             }
         }
         if (RecvString.Contains("PUBLICTIMESTAMP"))
         {
             if (RecvString.Split(';').Length == 2)
             {
                 string s = RecvString.Split(';')[1];
                 if (int.TryParse(s, out int v))
                 {
                     version = new VersionControl.Version(v);
                     if (ServerVersion.CheckVersion(v))
                     {
                         IsMatchVersion = true;
                     }
                 }
             }
             Send(DateTime.Now.ToBinary().ToString() + ";" + IsMatchVersion);
             return;
         }
         if (IsMatchVersion)
         {
             //登陆取到的设备
             ret = Program.LogDevice(RecvString);
             if (ret.IsSuccess)
             {
                 IsMatched = true;
                 UsedKey   = ret.InternalEx;
                 //在key:nick表中获取玩家昵称,若为空用Key的MD5值临时代替
                 NickName = Program.key_nick.GetFirstYWithX(UsedKey, GetMD5(UsedKey));
                 Send(ret.Value());
             }
             else
             {
                 if (ret.Note == "nomac")
                 {
                     if (genKey.Gen())
                     {
                         ret.Note = genKey.Result;
                     }
                 }
                 Send(ret.Value());
             }
         }
         return;
     }
     if (RecvParams.Length > 1)
     {
         if (RecvParams[0] == "map")
         {
             if (PlayerContext != null)
             {
                 PlayerContext.EvalCommand(RecvParams);
             }
             return;
         }
     }
     try
     {
         ServerResult sresult = OnRecvServerData();
         if (sresult != null)
         {
             Send(sresult);
         }
     }
     catch
     {
         ConsoleColor color = Console.ForegroundColor;
         Console.ForegroundColor = ConsoleColor.Red;
         Console.Write("在处理来自");
         SayPlayerInfo();
         Logger.WriteLine("的数据时,遇到了错误。");
         Logger.WriteLine("这通常说明此玩家有异常的游戏行为或使用了错误版本的客户端。");
         ForgetiveServer.Close(this);
         Console.ForegroundColor = color;
     }
 }