示例#1
0
 public void JoinRoom(string name, string password, string playerName, Dictionary <object, object> playerProperties)
 {
     RpcAsync(new JoinRoomInLobbyRequest()
     {
         Name     = name,
         Password = password
     }, result => {
         JoinRoomInLobbyReply reply = (JoinRoomInLobbyReply)result;
         if (reply.Result == JoinRoomResult.Success)
         {
             this.ToRoomClient.Connect(reply.RoomServerHostPort.Host, reply.RoomServerHostPort.Port, () => {
                 this.ToRoomClient.RpcAsync(new JoinRoomInRoomServerRequest()
                 {
                     Name             = name,
                     Password         = password,
                     PlayerName       = playerName,
                     PlayerProperties = playerProperties
                 }, joinResult => {
                     JoinRoomInRoomServerReply joinReply = (JoinRoomInRoomServerReply)joinResult;
                     if (joinReply.Result != JoinRoomResult.Success)
                     {
                         this.Log.Error("Join room fail : " + joinReply.Result);
                         this.RoomClient.Callback.OnJoinRoomFailed(joinReply.Result);
                     }
                     else
                     {
                         this.ToRoomClient.OnJoinRoom(joinReply);
                         this.Close(CloseCause.ClosedByClientLogic);
                     }
                 });
             }, exception => {
                 this.Log.Error("connect to room server fail", exception);
                 this.RoomClient.RunInMainThread(() => {
                     this.RoomClient.Callback.OnJoinRoomFailed(JoinRoomResult.ConnectToRoomServerFail);
                 });
             });
         }
         else
         {
             this.Log.Error("join room fail : " + reply.Result);
             this.RoomClient.Callback.OnJoinRoomFailed(reply.Result);
         }
     });
 }
示例#2
0
        internal void OnJoinRoom(JoinRoomInRoomServerReply reply)
        {
            this.JoiningRoom = false;
            Dictionary <int, RoomPlayer> players = new Dictionary <int, RoomPlayer>();

            this.Room                    = reply.Room;
            this.Room.Session            = this;
            this.Room.MinePlayer         = reply.SelfPlayer;
            this.Room.MinePlayer.Session = this;
            this.Room.MinePlayer.Room    = this.Room;
            players.Add(this.Room.MinePlayer.Id, this.Room.MinePlayer);
            foreach (RoomPlayer otherPlayerInfo in reply.OtherPlayers)
            {
                otherPlayerInfo.Session = null;
                otherPlayerInfo.Room    = this.Room;
                players.Add(otherPlayerInfo.Id, otherPlayerInfo);
            }
            this.Room.Players = players;
            this.RoomClient.Callback.OnJoinedRoom();
        }