public void JoinLocation(string location, bool joiningLocation = true)
 {
     PlayerData.Location = location;
     socket.Emit("set_location", PlayerData.Location);
     Debug.LogInfo($"Socket.IO Emit: 'set_location', sent data:\n{PlayerData.Location}\n", "NETWORK");
     SceneManager.Instance.LoadScene(joiningLocation ? $"{location}-Menu" : "Map");
 }
 public void NextQuestionMinigame3()
 {
     socket.Emit("request_minigame_3", new JObject {
         ["gameGuid"] = ActiveMinigame3.GUID
     }.ToString(Formatting.None));
     Debug.LogInfo($"Socket.IO Emit: 'request_minigame_3', sent data:\n{new JObject {["gameGuid"] = ActiveMinigame3.GUID}.ToString(Formatting.None)}\n", "NETWORK");
 }
 public void LeaveRoom()
 {
     socket.Emit("leave_room");
     Debug.LogInfo($"Socket.IO Emit: 'leave_room', sent data: \"\"", "NETWORK");
     SoundManager.Instance.StopPlaying("bar_ambiance");
     JoinLocation(PlayerData.Location);
 }
Exemplo n.º 4
0
        public void LoadScene(string sceneID)
        {
            MouseCursor.Instance.Normal();
            if (scenes.ContainsKey(activeSceneID))
            {
                Debug.LogInfo($"Unloaded scene `{activeSceneID}`.");
                scenes[activeSceneID].Unload();
                RemoveChild(scenes[activeSceneID]);
            }
            else
            {
                Debug.LogWarning($"Could not unload scene `{activeSceneID}`. Reason: Scene not found in Scene dictionary.");
            }

            activeSceneID = sceneID;
            if (scenes.ContainsKey(activeSceneID))
            {
                Debug.LogInfo($"Loaded scene `{activeSceneID}`.");
                scenes[activeSceneID].Load();
                AddChild(scenes[activeSceneID]);
            }
            else
            {
                Debug.LogWarning($"Could not load scene `{activeSceneID}`. Reason: Scene not found in Scene dictionary.");
            }
        }
 public void StopPlayingSound(string soundId)
 {
     socket.Emit("stop_playing_sound", new JObject {
         ["soundId"] = soundId
     }.ToString(Formatting.None));
     Debug.LogInfo($"Socket.IO Emit: 'stop_playing_sound', sent data:\n{new JObject {["soundId"] = soundId}.ToString(Formatting.None)}\n", "NETWORK");
     SoundManager.Instance.StopPlaying(soundId);
 }
 public void CreateAccount(string username, int avatarIndex, bool consent)
 {
     PlayerData.Username    = username;
     PlayerData.AvatarIndex = avatarIndex;
     PlayerData.Consent     = consent;
     socket.Emit("update_account", PlayerData.JSONString);
     Debug.LogInfo($"Socket.IO Emit: 'update_account', sent data:\n{PlayerData.JSONString}\n", "NETWORK");
 }
 public void PlaySound(string soundId, bool stopAlreadyPlaying)
 {
     socket.Emit("play_sound", new JObject {
         ["soundId"] = soundId, ["stopAlreadyPlaying"] = stopAlreadyPlaying
     }.ToString(Formatting.None));
     Debug.LogInfo($"Socket.IO Emit: 'play_sound', sent data:\n{new JObject {["soundId"] = soundId, ["stopAlreadyPlaying"] = stopAlreadyPlaying}.ToString(Formatting.None)}\n", "NETWORK");
     SoundManager.Instance.PlaySound(soundId, stopAlreadyPlaying);
 }
 public void StopPlayingMinigame3()
 {
     socket.Emit("finish_minigame_3", new JObject {
         ["gameGuid"] = ActiveMinigame3.GUID
     }.ToString(Formatting.None));
     Debug.LogInfo($"Socket.IO Emit: 'finish_minigame_3', sent data:\n{new JObject {["gameGuid"] = ActiveMinigame3.GUID}.ToString(Formatting.None)}\n", "NETWORK");
     Minigame3Element.ActiveMinigame.Deinitialize();
 }
        public void TryJoinRoom(string roomGuid, string roomCode)
        {
            var roomData = new JObject {
                ["guid"] = roomGuid, ["code"] = roomCode
            };

            socket.Emit("join_room", roomData.ToString(Formatting.None));
            Debug.LogInfo($"Socket.IO Emit: 'join_room', sent data:\n{roomData.ToString(Formatting.None)}\n", "NETWORK");
        }
 public void CreateAndJoinRoom(string roomName, string roomDesc, string code, bool isNSFW, bool isPublic)
 {
     ActiveRoom = new NetworkRoom(roomName, roomDesc, Guid.NewGuid().ToString(), code, PlayerData.Location, isPublic, isNSFW);
     ActiveRoom.Players.Add(PlayerData.GUID, PlayerData);
     PlayerData.RoomID = ActiveRoom.GUID;
     socket.Emit("create_room", ActiveRoom.JSONString);
     Debug.LogInfo($"Socket.IO Emit: 'create_room', sent data:\n{ActiveRoom.JSONString}\n", "NETWORK");
     SceneManager.Instance.LoadScene($"{PlayerData.Location}-Bar");
     SoundManager.Instance.PlaySound("bar_ambiance");
 }
        public void StartMinigame3()
        {
            var minigame3Data = new NetworkNeverHaveIEver(Guid.NewGuid().ToString(), PlayerData.GUID);

            ActiveMinigame3 = minigame3Data;
            var jsonData = minigame3Data.JSONObject;

            jsonData["roomGuid"] = ActiveRoom.GUID;
            socket.Emit("start_minigame_3", jsonData.ToString(Formatting.None));
            Debug.LogInfo($"Socket.IO Emit: 'start_minigame_3', sent data:\n{jsonData.ToString(Formatting.None)}\n", "NETWORK");
            socket.Emit("request_minigame_3", jsonData.ToString(Formatting.None));
            Debug.LogInfo($"Socket.IO Emit: 'request_minigame_3', sent data:\n{jsonData.ToString(Formatting.None)}\n", "NETWORK");
        }
        private void SetupSocket_Minigames_3()
        {
            socket.On("started_minigame_3", data => {
                Debug.LogInfo($"Socket.IO: 'started_minigame_3', received data:\n{data?.ToString()}\n", "NETWORK");
                var minigameData = (JObject)data;
                ActiveMinigame3  = new NetworkNeverHaveIEver(minigameData.Value <string>("gameGuid"), minigameData.Value <string>("ownerGuid"));
                startedMinigame3 = true;
            });
            socket.On("voted_minigame_3", data => {
                Debug.LogInfo($"Socket.IO: 'voted_minigame_3', received data:\n{data?.ToString()}\n", "NETWORK");
                var minigameData = (JObject)data;
                var redirect     = minigameData.TryGetValue("redirect", out _);
                ActiveMinigame3.SetVote(minigameData.Value <string>("guid"), minigameData.Value <string>("vote"));
                if (redirect)
                {
                    return;
                }
                if (ActiveMinigame3.Owner == PlayerData.GUID && ActiveMinigame3.IsQuestionDone)
                {
                    socket.Emit("results_minigame_3", "");
                    Debug.LogInfo($"Socket.IO Emit: 'results_minigame_3', sent data: \"\"", "NETWORK");
                    showResultsMinigame3 = true;
                }
                else
                {
                    newVoteMinigame3 = true;
                }
            });

            socket.On("request_minigame_3", data => {
                Debug.LogInfo($"Socket.IO: 'request_minigame_3', received data:\n{data?.ToString()}\n", "NETWORK");
                var minigameData  = (JObject)data;
                var questionIndex = minigameData.Value <int>("question");
                var question      = Minigame3Element.GetQuestion(questionIndex);
                ActiveMinigame3.StartNewQuestion(question);
                newQuestionMinigame3 = true;
            });
            socket.On("results_minigame_3", data => {
                Debug.LogInfo($"Socket.IO: 'results_minigame_3', received data:\n{data?.ToString()}\n", "NETWORK");
                showResultsMinigame3 = true;
            });
            socket.On("finished_minigame_3", data => {
                Debug.LogInfo($"Socket.IO: 'finished_minigame_3', received data:\n{data?.ToString()}\n", "NETWORK");
                finishedMinigame3 = true;
            });
        }
 private void SetupSocket_Basic()
 {
     socket.On("connect", data => {
         Debug.LogInfo($"Socket.IO: 'connect', received data:\n{data?.ToString()}\n", "NETWORK");
         if (!initialized)
         {
             clientLoggedIn = true;
         }
         initialized = true;
     });
     socket.On("disconnect", data => {
         Debug.LogInfo($"Socket.IO: 'disconnect', received data:\n{data?.ToString()}\n", "NETWORK");
         Debug.Log($"Client disconnected. Reason: {data}");
     });
     socket.On("request_account", data => {
         Debug.LogInfo($"Socket.IO: 'request_account', received data:\n{data?.ToString()}\n", "NETWORK");
         socket.Emit("request_account_success", PlayerData.JSONString);
         Debug.LogInfo($"Socket.IO Emit: 'request_account_success', sent data:\n{PlayerData.JSONString}\n", "NETWORK");
     });
 }
 public void VoteMinigame3(string playerGuid)
 {
     ActiveMinigame3.SetVote(PlayerData.GUID, playerGuid);
     if (ActiveMinigame3.Owner == PlayerData.GUID && ActiveMinigame3.IsQuestionDone)
     {
         socket.Emit("results_minigame_3", "");
         Debug.LogInfo($"Socket.IO Emit: 'results_minigame_3', sent data: \"\"", "NETWORK");
         socket.Emit("voted_minigame_3", new JObject {
             ["guid"] = PlayerData.GUID, ["vote"] = playerGuid, ["redirect"] = false
         }.ToString(Formatting.None));
         Debug.LogInfo($"Socket.IO Emit: 'voted_minigame_3', sent data:\n{new JObject {["guid"] = PlayerData.GUID, ["vote"] = playerGuid, ["redirect"] = false}.ToString(Formatting.None)}\n", "NETWORK");
         showResultsMinigame3 = true;
     }
     else
     {
         socket.Emit("voted_minigame_3", new JObject {
             ["guid"] = PlayerData.GUID, ["vote"] = playerGuid
         }.ToString(Formatting.None));
         Debug.LogInfo($"Socket.IO Emit: 'voted_minigame_3', sent data:\n{new JObject {["guid"] = PlayerData.GUID, ["vote"] = playerGuid}.ToString(Formatting.None)}\n", "NETWORK");
     }
 }
        private void SetupSocket_Sound()
        {
            socket.On("play_sound", data => {
                Debug.LogInfo($"Socket.IO: 'play_sound', received data:\n{data?.ToString()}\n", "NETWORK");
                var jsonData           = (JObject)data;
                var soundId            = jsonData.Value <string>("soundId");
                var stopAlreadyPlaying = jsonData.Value <bool>("stopAlreadyPlaying");
                if (soundId.StartsWith("Song"))
                {
                    JukeboxElement.ActiveJukebox.CurrentlyPlaying = soundId;
                }

                SoundManager.Instance.PlaySound(soundId, stopAlreadyPlaying);
            });

            socket.On("stop_playing_sound", data => {
                Debug.LogInfo($"Socket.IO: 'stop_playing_sound', received data:\n{data?.ToString()}\n", "NETWORK");
                var jsonData = (JObject)data;
                var soundId  = jsonData.Value <string>("soundId");
                SoundManager.Instance.StopPlaying(soundId);
            });
        }
 public void RequestRooms()
 {
     socket.Emit("request_rooms");
     Debug.LogInfo($"Socket.IO Emit: 'join_room', sent data: \"\"", "NETWORK");
 }
        private void SetupSocket_Rooms()
        {
            socket.On("request_rooms_success", data => {
                Debug.LogInfo($"Socket.IO: 'request_rooms_success', received data:\n{data?.ToString()}\n", "NETWORK");
                Rooms       = new List <NetworkRoom>();
                var objData = (JObject)data;
                foreach (var prop in objData.Properties())
                {
                    var roomData = (JObject)objData[prop.Name];
                    var room     = new NetworkRoom(roomData.Value <string>("name"), roomData.Value <string>("desc"), roomData.Value <string>("guid"), roomData.Value <string>("code"), roomData.Value <string>("type"), roomData.Value <bool>("pub"), roomData.Value <bool>("nsfw"));
                    Rooms.Add(room);
                }

                RoomsReady = true;
            });
            socket.On("create_room_success", data => { Debug.LogInfo($"Socket.IO: 'create_room_success', received data:\n{data?.ToString()}\n", "NETWORK"); });
            socket.On("join_room_failed", data => {
                Debug.LogInfo($"Socket.IO: 'join_room_failed', received data:\n{data?.ToString()}\n", "NETWORK");
                Debug.LogWarning("Socket.IO response not implemented for 'join_room_failed'");
            });
            socket.On("join_room_success", data => {
                Debug.LogInfo($"Socket.IO: 'join_room_success', received data:\n{data?.ToString()}\n", "NETWORK");
                var roomData      = (JObject)data;
                ActiveRoom        = new NetworkRoom(roomData.Value <string>("name"), roomData.Value <string>("desc"), roomData.Value <string>("guid"), roomData.Value <string>("code"), roomData.Value <string>("type"), roomData.Value <bool>("pub"), roomData.Value <bool>("nsfw"));
                PlayerData.RoomID = ActiveRoom.GUID;
                ActiveRoom.Players.Add(PlayerData.GUID, PlayerData);
                joinRoomSuccess = true;
                socket.Emit("request_players", ActiveRoom.GUID);
                Debug.LogInfo($"Socket.IO Emit: 'request_players', sent data:\n{ActiveRoom.GUID}\n", "NETWORK");
            });
            socket.On("request_players_success", data => {
                Debug.LogInfo($"Socket.IO: 'request_players_success', received data:\n{data?.ToString()}\n", "NETWORK");
                var playerData = (JObject)data;
                foreach (var playerId in playerData.Properties())
                {
                    var networkPlayerData = new NetworkPlayer(playerData[playerId.Name].Value <string>("username"), playerData[playerId.Name].Value <string>("guid"), playerData[playerId.Name].Value <string>("room"), playerData[playerId.Name].Value <string>("location"), playerData[playerId.Name].Value <int>("avatar"), playerData[playerId.Name].Value <bool>("consent"));
                    ActiveRoom.Players.Add(playerId.Name, networkPlayerData);
                }
            });
            socket.On("client_joined", data => {
                Debug.LogInfo($"Socket.IO: 'client_joined', received data:\n{data?.ToString()}\n", "NETWORK");
                if (PlayerData.RoomID == "none")
                {
                    return;
                }
                var playerData = (JObject)data;
                newestMessage  = new ChatMessage("SERVER", "00000000-0000-0000-0000-000000000000", $"`{playerData.Value<string>("username")}` joined the room!");
                ActiveRoom.Players.Add(playerData.Value <string>("guid"), new NetworkPlayer()
                {
                    AvatarIndex = playerData.Value <int>("avatar"), Username = playerData.Value <string>("username"), GUID = playerData.Value <string>("guid")
                });
                SoundManager.Instance.PlaySound("client_joined");
                gotNewMessage = true;
            });

            socket.On("new_message", data => {
                Debug.LogInfo($"Socket.IO: 'new_message', received data:\n{data?.ToString()}\n", "NETWORK");
                newestMessage = ChatMessage.FromJSON(JObject.Parse(((JObject)data).Value <string>("message")));
                gotNewMessage = true;
            });

            socket.On("client_disconnected", data => {
                Debug.LogInfo($"Socket.IO: 'client_disconnected', received data:\n{data?.ToString()}\n", "NETWORK");
                if (PlayerData.RoomID == "none")
                {
                    return;
                }
                var playerData = (JObject)data;
                newestMessage  = new ChatMessage("SERVER", "00000000-0000-0000-0000-000000000000", $"`{playerData.Value<string>("username")}` left the room!");
                ActiveRoom.Players.Remove(playerData.Value <string>("guid"));
                SoundManager.Instance.PlaySound("client_left", true);
                gotNewMessage = true;
            });
        }
 public void SendMessage(ChatMessage message)
 {
     socket.Emit("send_message", message.JSONString);
     Debug.LogInfo($"Socket.IO Emit: 'send_message', sent data:\n{message.JSONString}\n", "NETWORK");
 }