예제 #1
0
        public void InterHall(Client client, bool reconnect)
        {
            try
            {
                //update user profile
                //bring to hall
                bool proceed = client.GetProfile(!reconnect);
                if (!proceed)
                {
                    return;
                }

                clientList.TryAdd(client.UserID, client.Profile.NickName);
                //更新到form1
                Dictionary <int, string> client_list = clientList.ToDictionary(entry => entry.Key, entry => entry.Value);
                UpdateUsers(client_list);

                UId2ClientTable.TryGetValue(client.UserID, out Client temp);

                MyData data = new MyData();
                if (!reconnect)
                {
                    //发送当前已登录的其他玩家信息和游戏房间信息
                    Dictionary <int, RoomInfoStruct> ds = RoomList.Instance().GetRoomList();
                    data = new MyData
                    {
                        Description = PacketDescription.Hall2Cient,
                        Protocol    = Protocol.GetProfile,
                        Body        = new List <string> {
                            JsonUntity.Dictionary2Json(client_list), JsonUntity.Object2Json(ds)
                        }
                    };
                    client.SendProfileReply(data);
                }

                //通知其他客户端更新
                data = new MyData()
                {
                    Description = PacketDescription.Hall2Cient,
                    Protocol    = Protocol.UpdateHallJoin,
                    Body        = new List <string> {
                        client.UserID.ToString(), client.Profile.NickName, "0"
                    }
                };

                List <Client> clients = new List <Client>(UId2ClientTable.Values);
                foreach (Client other in clients)
                {
                    if (other != client)
                    {
                        other.SendProfileReply(data);
                    }
                }
            }
            catch (Exception e)
            {
                LogHelper.WriteLog(null, e);
                Debug(string.Format("error on inter hall {0} {1}", e.Message, e.TargetSite));
            }
        }
예제 #2
0
        public void InterHall(Client client, bool reconnect)
        {
            //update user profile
            //bring to hall
            bool proceed = client.GetProfile(!reconnect);

            if (!proceed)
            {
                return;
            }

            ClientList.Instance().AddClient(client.UserID, client.Profile.NickName);
            //更新到form1
            UpdateUsers(ClientList.Instance().GetUserList(0));

            MyData data = new MyData();

            if (!reconnect)
            {
                //发送当前已登录的其他玩家信息和游戏房间信息
                DataSet ds = new DataSet();
                ds.Tables.Add(ClientList.Instance().GetUserList(0).Copy());
                ds.Tables.Add(RoomList.Instance().GetRoomList().Copy());

                data = new MyData
                {
                    Description = PacketDescription.Hall2Cient,
                    Protocol    = protocol.GetProfile,
                    Body        = new List <string> {
                        JsonUntity.DataSet2Json(ds)
                    }
                };
                client.SendProfileReply(data);
            }

            //通知其他客户端更新
            data = new MyData()
            {
                Description = PacketDescription.Hall2Cient,
                Protocol    = protocol.UpdateHallJoin,
                Body        = new List <string> {
                    client.UserID.ToString(), client.Profile.NickName, "0"
                }
            };
            foreach (Client other in UId2ClientTable.Values)
            {
                if (other != client)
                {
                    other.SendProfileReply(data);
                }
            }
        }