TypedLobby









How do I use Typed Lobby
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: LoadbalancingPeer.cs Copy
48         public virtual bool OpJoinLobby(TypedLobby lobby)
49         {
50             if (this.DebugOut >= DebugLevel.INFO)
51             {
52                 this.Listener.DebugReturn(DebugLevel.INFO, "OpJoinLobby()");
53             }
54
55             Dictionary parameters = null;
56             if (lobby != null && !lobby.IsDefault)
57             {
58                 parameters = new Dictionary();
59                 parameters[(byte)ParameterCode.LobbyName] = lobby.Name;
60                 parameters[(byte)ParameterCode.LobbyType] = (byte)lobby.Type;
61             }
62
63             return this.OpCustom(OperationCode.JoinLobby, parameters, true);
64         }
File name: LoadbalancingPeer.cs Copy
86         public virtual bool OpCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby lobby, Hashtable playerProperties, bool onGameServer)
87         {
88             if (this.DebugOut >= DebugLevel.INFO)
89             {
90                 this.Listener.DebugReturn(DebugLevel.INFO, "OpCreateRoom()");
91             }
92
93             Dictionary op = new Dictionary();
94
95             if (!string.IsNullOrEmpty(roomName))
96             {
97                 op[ParameterCode.RoomName] = roomName;
98             }
99             if (lobby != null)
100             {
101                 op[ParameterCode.LobbyName] = lobby.Name;
102                 op[ParameterCode.LobbyType] = (byte)lobby.Type;
103             }
104
105             if (onGameServer)
106             {
107                 if (playerProperties != null && playerProperties.Count > 0)
108                 {
109                     op[ParameterCode.PlayerProperties] = playerProperties;
110                     op[ParameterCode.Broadcast] = true; // TODO: check if this also makes sense when creating a room?! // broadcast actor properties
111                 }
112
113
114                 if (roomOptions == null)
115                 {
116                     roomOptions = new RoomOptions();
117                 }
118
119                 Hashtable gameProperties = new Hashtable();
120                 op[ParameterCode.GameProperties] = gameProperties;
121                 gameProperties.MergeStringKeys(roomOptions.customRoomProperties);
122
123                 gameProperties[GameProperties.IsOpen] = roomOptions.isOpen; // TODO: check default value. dont send this then
124                 gameProperties[GameProperties.IsVisible] = roomOptions.isVisible; // TODO: check default value. dont send this then
125                 gameProperties[GameProperties.PropsListedInLobby] = roomOptions.customRoomPropertiesForLobby;
126                 if (roomOptions.maxPlayers > 0)
127                 {
128                     gameProperties[GameProperties.MaxPlayers] = roomOptions.maxPlayers;
129                 }
130                 if (roomOptions.cleanupCacheOnLeave)
131                 {
132                     op[ParameterCode.CleanupCacheOnLeave] = true; // this is actually setting the room's config
133                     gameProperties[GameProperties.CleanupCacheOnLeave] = true; // this is only informational for the clients which join
134                 }
135             }
136
137             // UnityEngine.Debug.Log("CreateGame: " + SupportClass.DictionaryToString(op));
138             return this.OpCustom(OperationCode.CreateGame, op, true);
139         }
File name: LoadbalancingPeer.cs Copy
143         public virtual bool OpJoinRoom(string roomName, RoomOptions roomOptions, TypedLobby lobby, bool createIfNotExists, Hashtable playerProperties, bool onGameServer)
144         {
145             Dictionary op = new Dictionary();
146
147             if (!string.IsNullOrEmpty(roomName))
148             {
149                 op[ParameterCode.RoomName] = roomName;
150             }
151             if (createIfNotExists)
152             {
153                 op[ParameterCode.CreateIfNotExists] = true;
154                 if (lobby != null)
155                 {
156                     op[ParameterCode.LobbyName] = lobby.Name;
157                     op[ParameterCode.LobbyType] = (byte)lobby.Type;
158                 }
159             }
160
161             if (onGameServer)
162             {
163                 if (playerProperties != null && playerProperties.Count > 0)
164                 {
165                     op[ParameterCode.PlayerProperties] = playerProperties;
166                     op[ParameterCode.Broadcast] = true; // broadcast actor properties
167                 }
168
169
170                 if (createIfNotExists)
171                 {
172                     if (roomOptions == null)
173                     {
174                         roomOptions = new RoomOptions();
175                     }
176
177                     Hashtable gameProperties = new Hashtable();
178                     op[ParameterCode.GameProperties] = gameProperties;
179                     gameProperties.MergeStringKeys(roomOptions.customRoomProperties);
180
181                     gameProperties[GameProperties.IsOpen] = roomOptions.isOpen;
182                     gameProperties[GameProperties.IsVisible] = roomOptions.isVisible;
183                     gameProperties[GameProperties.PropsListedInLobby] = roomOptions.customRoomPropertiesForLobby;
184                     if (roomOptions.maxPlayers > 0)
185                     {
186                         gameProperties[GameProperties.MaxPlayers] = roomOptions.maxPlayers;
187                     }
188                     if (roomOptions.cleanupCacheOnLeave)
189                     {
190                         op[ParameterCode.CleanupCacheOnLeave] = true; // this is actually setting the room's config
191                         gameProperties[GameProperties.CleanupCacheOnLeave] = true; // this is only informational for the clients which join
192                     }
193                 }
194             }
195
196             // UnityEngine.Debug.Log("JoinGame: " + SupportClass.DictionaryToString(op));
197             return this.OpCustom(OperationCode.JoinGame, op, true);
198         }
File name: LoadbalancingPeer.cs Copy
212         public virtual bool OpJoinRandomRoom(Hashtable expectedCustomRoomProperties, byte expectedMaxPlayers, Hashtable playerProperties, MatchmakingMode matchingType, TypedLobby typedLobby, string sqlLobbyFilter)
213         {
214             if (this.DebugOut >= DebugLevel.INFO)
215             {
216                 this.Listener.DebugReturn(DebugLevel.INFO, "OpJoinRandomRoom()");
217             }
218
219             Hashtable expectedRoomProperties = new Hashtable();
220             expectedRoomProperties.MergeStringKeys(expectedCustomRoomProperties);
221             if (expectedMaxPlayers > 0)
222             {
223                 expectedRoomProperties[GameProperties.MaxPlayers] = expectedMaxPlayers;
224             }
225
226             Dictionary opParameters = new Dictionary();
227             if (expectedRoomProperties.Count > 0)
228             {
229                 opParameters[ParameterCode.GameProperties] = expectedRoomProperties;
230             }
231
232             if (playerProperties != null && playerProperties.Count > 0)
233             {
234                 opParameters[ParameterCode.PlayerProperties] = playerProperties;
235             }
236
237             if (matchingType != MatchmakingMode.FillRoom)
238             {
239                 opParameters[ParameterCode.MatchMakingType] = (byte)matchingType;
240             }
241
242             if (typedLobby != null)
243             {
244                 opParameters[ParameterCode.LobbyName] = typedLobby.Name;
245                 opParameters[ParameterCode.LobbyType] = (byte)typedLobby.Type;
246             }
247
248             if (!string.IsNullOrEmpty(sqlLobbyFilter))
249             {
250                 opParameters[ParameterCode.Data] = sqlLobbyFilter;
251             }
252
253             // UnityEngine.Debug.LogWarning("OpJoinRandom: " + opParameters.ToStringFull());
254             return this.OpCustom(OperationCode.JoinRandomGame, opParameters, true);
255         }
File name: NetworkingPeer.cs Copy
99     internal TypedLobby mRoomToEnterLobby { get; set; }
File name: NetworkingPeer.cs Copy
125     public TypedLobby lobby { get; set; }
File name: NetworkingPeer.cs Copy
185     public NetworkingPeer(IPhotonPeerListener listener, string playername, ConnectionProtocol connectionProtocol) : base(listener, connectionProtocol)
186     {
187         #if !UNITY_EDITOR && (UNITY_WINRT)
188         // this automatically uses a separate assembly-file with Win8-style Socket usage (not possible in Editor)
189         Debug.LogWarning("Using PingWindowsStore");
190         PhotonHandler.PingImplementation = typeof(PingWindowsStore); // but for ping, we have to set the implementation explicitly to Win 8 Store/Phone
191         #endif
192
193         #pragma warning disable 0162 // the library variant defines if we should use PUN's SocketUdp variant (at all)
194         if (PhotonPeer.NoSocket)
195         {
196             #if !UNITY_EDITOR && (UNITY_PS3 || UNITY_ANDROID)
197             Debug.Log("Using class SocketUdpNativeDynamic");
198             this.SocketImplementation = typeof(SocketUdpNativeDynamic);
199             PhotonHandler.PingImplementation = typeof(PingNativeDynamic);
200             #elif !UNITY_EDITOR && UNITY_IPHONE
201             Debug.Log("Using class SocketUdpNativeStatic");
202             this.SocketImplementation = typeof(SocketUdpNativeStatic);
203             PhotonHandler.PingImplementation = typeof(PingNativeStatic);
204             #elif !UNITY_EDITOR && (UNITY_WINRT)
205             // this automatically uses a separate assembly-file with Win8-style Socket usage (not possible in Editor)
206             #else
207             this.SocketImplementation = typeof (SocketUdp);
208             PhotonHandler.PingImplementation = typeof(PingMonoEditor);
209             #endif
210
211             if (this.SocketImplementation == null)
212             {
213                 Debug.Log("No socket implementation set for 'NoSocket' assembly. Please contact Exit Games.");
214             }
215         }
216         #pragma warning restore 0162
217
218         if (PhotonHandler.PingImplementation == null)
219         {
220             PhotonHandler.PingImplementation = typeof(PingMono);
221         }
222
223         this.Listener = this;
224         this.lobby = TypedLobby.Default;
225         this.LimitOfUnreliableCommands = 40;
226
227         // don't set the field directly! the listener is passed on to other classes, which get updated by the property set method
228         this.externalListener = listener;
229         this.PlayerName = playername;
230         this.mLocalActor = new PhotonPlayer(true, -1, this.playername);
231         this.AddNewPlayer(this.mLocalActor.ID, this.mLocalActor);
232
233         // RPC shortcut lookup creation (from list of RPCs, which is updated by Editor scripts)
234         rpcShortcuts = new Dictionary(PhotonNetwork.PhotonServerSettings.RpcList.Count);
235         for (int index = 0; index < PhotonNetwork.PhotonServerSettings.RpcList.Count; index++)
236         {
237             var name = PhotonNetwork.PhotonServerSettings.RpcList[index];
238             rpcShortcuts[name] = index;
239         }
240
241         this.State = global::PeerState.PeerCreated;
242     }
File name: NetworkingPeer.cs Copy
932     public bool OpCreateGame(string roomName, RoomOptions roomOptions, TypedLobby typedLobby)
933     {
934         bool onGameServer = this.server == ServerConnection.GameServer;
935         if (!onGameServer)
936         {
937             this.mRoomOptionsForCreate = roomOptions;
938             this.mRoomToGetInto = new Room(roomName, roomOptions);
939             this.mRoomToEnterLobby = typedLobby ?? ((this.insideLobby) ? this.lobby : null); // use given lobby, or active lobby (if any active) or none
940         }
941
942         this.mLastJoinType = JoinType.CreateGame;
943         return base.OpCreateRoom(roomName, roomOptions, this.mRoomToEnterLobby, this.GetLocalActorProperties(), onGameServer);
944     }
File name: NetworkingPeer.cs Copy
947     public bool OpJoinRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby, bool createIfNotExists)
948     {
949         bool onGameServer = this.server == ServerConnection.GameServer;
950         if (!onGameServer)
951         {
952             // roomOptions and typedLobby will be null, unless createIfNotExists is true
953             this.mRoomOptionsForCreate = roomOptions;
954             this.mRoomToGetInto = new Room(roomName, roomOptions);
955             this.mRoomToEnterLobby = null;
956             if (createIfNotExists)
957             {
958                 this.mRoomToEnterLobby = typedLobby ?? ((this.insideLobby) ? this.lobby : null); // use given lobby, or active lobby (if any active) or none
959             }
960         }
961
962         this.mLastJoinType = (createIfNotExists) ? JoinType.JoinOrCreateOnDemand : JoinType.JoinGame;
963         return base.OpJoinRoom(roomName, roomOptions, this.mRoomToEnterLobby, createIfNotExists, this.GetLocalActorProperties(), onGameServer);
964     }
File name: NetworkingPeer.cs Copy
968     public override bool OpJoinRandomRoom(Hashtable expectedCustomRoomProperties, byte expectedMaxPlayers, Hashtable playerProperties, MatchmakingMode matchingType, TypedLobby typedLobby, string sqlLobbyFilter)
969     {
970         this.mRoomToGetInto = new Room(null, null);
971         this.mRoomToEnterLobby = null; // join random never stores the lobby. the following join will not affect the room lobby
972         // if typedLobby is null, the server will automatically use the active lobby or default, which is what we want anyways
973
974         this.mLastJoinType = JoinType.JoinRandomGame;
975         return base.OpJoinRandomRoom(expectedCustomRoomProperties, expectedMaxPlayers, playerProperties, matchingType, typedLobby, sqlLobbyFilter);
976     }

TypedLobby 119 lượt xem

Gõ tìm kiếm nhanh...