public override void DoCommand()
        {
            int command = BitConverter.ToInt32(bytes, 8);

            conn.ID = BitConverter.ToInt32(bytes, 12).ToString();

            switch (command)
            {
            case _HeartBeat:
                // Console.WriteLine("收到"+ conn.ID + "的心跳命令---" +DateTime.Now);
                ConnTime connTime = new ConnTime(conn, DateTime.Now);
                Server.AddHeartTime(conn.ID, connTime);
                break;

            case _ReLink:
                PersonalInfo.ChangeStatusInfo(int.Parse(conn.ID), "", (int)PersonStatus.OnLine);
                Console.WriteLine("玩家" + conn.ID + "重连" + DateTime.Now);
                Conn receiver_conn;
                if (Server.connMap.TryGetValue(conn.ID, out receiver_conn))
                {
                    Console.WriteLine("修改成功Conn" + conn.ID + "重连" + DateTime.Now);

                    Server.connMap[conn.ID] = conn;
                }
                else
                {
                    Console.WriteLine("connMap不存在改Id" + conn.ID + "重连" + DateTime.Now);
                    Server.connMap.Add(conn.ID, conn);
                }
                break;
            }
        }
예제 #2
0
 /// <summary>
 /// 添加在线的客户端
 /// </summary>
 /// <param name="id"></param>
 /// <param name="heartInfo"></param>
 public static void AddHeartTime(string id, ConnTime heartInfo)
 {
     if (connHeartTime != null)
     {
         if (connHeartTime.ContainsKey(id)) //判断是否已存在时间
         {
             connHeartTime[id] = heartInfo; //覆盖时间
         }
         else
         {
             connHeartTime.Add(id, heartInfo);//添加项
         }
     }
 }