Пример #1
0
 public void CreateRoom(string name, int maxPlayerCount, string password,
                        Dictionary <object, object> lobbyCustomProperties,
                        Dictionary <object, object> otherCustomProperties,
                        string playerName,
                        Dictionary <object, object> playerProperties)
 {
     RpcAsync(new CreateRoomInLobbyRequest()
     {
         Name                  = name,
         Password              = password,
         MaxPlayerCount        = maxPlayerCount,
         LobbyCustomProperties = lobbyCustomProperties
     }, result => {
         CreateRoomInLobbyReply reply = (CreateRoomInLobbyReply)result;
         if (reply.Result == CreateRoomResult.Success)
         {
             this.ToRoomClient.Connect(reply.RoomServerHostPort.Host, reply.RoomServerHostPort.Port, () => {
                 CreateRoomInRoomServerRequest createRequest = new CreateRoomInRoomServerRequest()
                 {
                     Name                  = reply.Name,
                     MaxPlayerCount        = maxPlayerCount,
                     Password              = password,
                     LobbyCustomProperties = lobbyCustomProperties,
                     OtherCustomProperties = otherCustomProperties,
                     Token                 = reply.Token,
                     PlayerName            = playerName,
                     PlayerProperties      = playerProperties
                 };
                 this.ToRoomClient.RpcAsync(createRequest, joinResult => {
                     CreateRoomInRoomServerReply joinReply = (CreateRoomInRoomServerReply)joinResult;
                     if (joinReply.Result != JoinRoomResult.Success)
                     {
                         this.Log.Error("Create room fail when join: " + reply.Result);
                         this.RoomClient.Callback.OnCreateRoomFailed(reply.Result);
                     }
                     else
                     {
                         this.ToRoomClient.OnCreatedRoom(joinReply);
                         Close(CloseCause.ClosedByClientLogic);
                     }
                 });
             }, exception => {
                 this.Log.Error("connect to room server fail", exception);
                 this.RoomClient.RunInMainThread(() => {
                     this.RoomClient.Callback.OnCreateRoomFailed(CreateRoomResult.ConnectToRoomServerFail);
                 });
             });
         }
         else
         {
             this.Log.Error("create room in lobby fail :" + reply.Result);
             this.RoomClient.Callback.OnCreateRoomFailed(reply.Result);
         }
     });
 }
Пример #2
0
        internal void OnCreatedRoom(CreateRoomInRoomServerReply 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.Room    = this.Room;
                otherPlayerInfo.Session = null;
                players.Add(otherPlayerInfo.Id, otherPlayerInfo);
            }
            this.Room.Players = players;
            this.RoomClient.Callback.OnCreatedRoom();
        }