Example #1
0
    /// <summary>
    ///     Handles a request from game server to teleport
    ///     user to another game server / zone.
    /// </summary>
    /// <param name="message"></param>
    public virtual void HandleTeleportRequest(IIncommingMessage message)
    {
        var request = message.Deserialize(new TeleportRequestPacket());

        var user = AuthModule.GetLoggedInUser(request.Username);
        var peer = user.Peer;

        // Find the room which represents the zone we need
        var room = RoomsModule.GetAllRooms()
                   .Where(s => s.Options.Properties.ContainsKey(ZoneNameKey))
                   .FirstOrDefault(s => s.Options.Properties[ZoneNameKey] == request.ZoneName);

        if (room == null)
        {
            // If no room with that zone name was found
            message.Respond("Zone was not found", ResponseStatus.Failed);
            return;
        }

        var accessRequestProperties = new Dictionary <string, string> {
            // Add the new position to the request
            // So that new server knows where exactly to position the player
            { ZonePosition, request.Position }
        };

        // Request an access to room
        room.GetAccess(peer, accessRequestProperties, (access, error) => {
            if (access == null)
            {
                // We didn't get the access
                message.Respond("Failed to get access to the zone: " + error, ResponseStatus.Failed);
                return;
            }

            // We have the access to new zone, let's store it
            // so player can request it when he's on the loading screen
            peer.SetProperty(WorldDemoPropCodes.ZoneAccess, access);

            // Notify game server that access was received
            message.Respond(ResponseStatus.Success);
        });
    }
Example #2
0
    IEnumerator StartSpawnServerRoutine()
    {
        while (true)
        {
            yield return(new WaitForSeconds(countPlayersToCreateNewRoomDuration));

            if (roomsModule != null && spawnersModule != null)
            {
                // Clear room counter
                foreach (var roomCount in roomCounts)
                {
                    roomCounts[roomCount.Key].roomCount   = 0;
                    roomCounts[roomCount.Key].playerCount = 0;
                }

                // Count room and players
                var rooms = roomsModule.GetAllRooms().ToList();
                foreach (var room in rooms)
                {
                    var sceneName = room.Options.Properties[MsfDictKeys.SceneName];
                    if (roomCounts.ContainsKey(sceneName))
                    {
                        roomCounts[sceneName].roomCount   += 1;
                        roomCounts[sceneName].playerCount += room.OnlineCount;
                    }
                }

                foreach (var roomInfo in roomInfos)
                {
                    var sceneName = roomInfo.scene.SceneName;
                    if (roomCounts[sceneName].roomCount == 0)
                    {
                        roomCounts[sceneName].roomId = 0;
                        SpawnScene(roomInfo, true);
                    }
                    else
                    {
                        // If there are only first room, reset room Id
                        if (roomCounts[sceneName].roomCount == 1)
                        {
                            roomCounts[sceneName].roomId = 1;
                        }
                        if (Mathf.FloorToInt(roomCounts[sceneName].playerCount / rooms.Count) >= roomInfo.playersAmountToCreateNewRoom)
                        {
                            SpawnScene(roomInfo, false);
                        }
                    }
                }
            }
        }
    }