/** Set user code and room number * @param aUcode user code * @param roomNumber room number * @return True if codes are valid, false otherwise */ public bool SetCode(int aUcode, int roomNumber) { UXPlayerController player = UXPlayerController.Instance; int lcode = GetRoomNumber(); int ucode = -1; if (lcode != -1) { ucode = player.GetCode(); } else { lcode = roomNumber; ucode = aUcode; } if (lcode == -1 || ucode == -1) { return(false); } launcherCode = lcode; player.SetCode(ucode); return(true); }
/** Send leave message */ public void Leave() { UXPlayerController player = UXPlayerController.Instance; string sendString = "{\"cmd\":\"leave_user\",\"u_code\":\"" + player.GetCode() + "\",\"l_code\":\"" + UXConnectController.GetRoomNumber() + "\"}" + DATA_DELIMITER; Send(sendString); }
/** Send game start message * @see OnGameStartHandler */ public void SendStartGame() { int userCode = player.GetCode(); string sendString = "{\"cmd\":\"start_game\",\"l_code\":\"" + room.RoomNumber + "\",\"u_code\":\"" + userCode + "\"}" + DATA_DELIMITER; Send(sendString); //{"cmd:"start_game",l_code":"launcherCode"}232 }
/** Request for user list * @see OnUserListReceived */ public void RefreshUserListFromServer() { UXPlayerController player = UXPlayerController.Instance; string msg = "{\"cmd\":\"get_user_list\",\"u_code\":\"" + player.GetCode() + "\",\"l_code\":\"" + room.RoomNumber + "\"}" + DATA_DELIMITER; Send(msg);//{"cmd":"get_user_list","l_code":"launcherCode"}232 Debug.Log("RefreshUserListFromServer!!"); }
/** Send join message */ public override void Join(string packageName) //data는쓰레기 호출할때도 "none" { Debug.Log("Join"); UXPlayerController playerController = UXPlayerController.Instance; int userCode = playerController.GetCode(); string name = playerController.GetName(); string msg = "{\"cmd\":\"join\",\"type\":\"user\",\"l_code\":\"" + room.RoomNumber + "\",\"u_code\":\"" + userCode + "\",\"name\":\"" + name + "\",\"max_user\":\"0\", \"package_name\" : \"" + packageName + "\"}" + DATA_DELIMITER; Debug.Log(msg); Send(msg); //{"cmd":"join","type":"user","l_code":"launcherCode","u_code":"userCode","name":"name","max_user":"******"}232 }
/** Send join message * @param roomNumber room number */ public override void Join(string data) { Debug.Log("Join"); UXPlayerController player = UXPlayerController.Instance; if (player.IsUserLogin() == false) { OnJoinFailed(JOIN_ERROR_NOT_LOGIN); return; } string sendString = "{\"cmd\":\"join_user\",\"u_code\":\"" + player.GetCode() + "\",\"u_name\":\"" + player.GetName() + "\",\"l_code\":\"" + launcherCode + "\"}" + DATA_DELIMITER; Debug.Log("sen " + sendString); Send(sendString); }
/** Set player's lobby state * @param state lobby state * @see UXUser.LobbyState */ public void SetPlayerState(UXUser.LobbyState state) { UXPlayerController player = UXPlayerController.Instance; player.SetLobbyState(state); string stateString = ""; if (state == UXUser.LobbyState.Ready) { stateString = "ready"; } else { stateString = "wait"; } string sendString = "{\"cmd\":\"change_lobby_state\",\"u_code\":\"" + player.GetCode() + "\",\"l_code\":\"" + room.RoomNumber + "\",\"state\":\"" + stateString + "\"}" + UXConnectController.DATA_DELIMITER; //<-? Send(sendString); //{"cmd":change_lobby_state","u_code":player.GetCode()","l_code":"GetRoomNumber()","state":stateString"}232 }
/** Send message to server * @param data left,right - Scroll direction, click - click index * @param buttonType "ok", "up", "down", "left", "right", "back", "click" */ public void SendData(string data, string buttonType) { UXPlayerController player = UXPlayerController.Instance; string sendString = "{\"cmd\":\"pad_button_touch\",\"u_code\":\"" + player.GetCode() + "\",\"l_code\":\"" + UXConnectController.GetRoomNumber() + "\",\"data\":\"" + data + "\",\"button_type\":\"" + buttonType + "\"}" + DATA_DELIMITER; Send(sendString); }
protected void ProcessReceivedMessage(string data) { if (string.IsNullOrEmpty(data) == true || data.Length <= 0) { Debug.Log("Empty"); //data 비어있떠 return; } Debug.Log("UXConnectController ProcessReceivedMessage data : " + data); var N = JSON.Parse(data); string command = N["cmd"]; if (command == "ack_result") { if (isSendAck == true && ackSender != null) //x { ackSender.ReceiveResult(); } } else if (command == "user_add") { int code = N ["u_code"].AsInt; string name = ParseUser(N ["name"]); UXUser userObj = new UXUser(name, code); Debug.Log("UserAdd : " + name); room.AddUser(userObj); var array = N ["user_list"]; if (array != null) { List <UXUser> list = ParseUserList((JSONArray)array); //리스트 갱신 room.UpdateUserList(list); } if (OnUserAdded != null) { int userIndex = GetUserIndexFromCode(code); OnUserAdded(userIndex, code); //playerCount 갱신, index 증가 -> index는 접속할 유저에게 할당할 index +이벤트 하나더 (로비매니저) } } else if (command == "user_del") { int code = N ["u_code"].AsInt; int userIndex = GetUserIndexFromCode(code); Debug.Log("UserDel: " + userIndex); if (OnGetRemovedIndex != null) { OnGetRemovedIndex(userIndex); } room.RemoveUser(userIndex); var array = N ["user_list"]; if (array != null) { List <UXUser> list = ParseUserList((JSONArray)array); room.UpdateUserList(list); } if (!isGameStarted) { if (OnUserRemoved != null) { OnUserRemoved(name, code); } } else { if (OnUserLeavedInGame != null) { OnUserLeavedInGame(userIndex, code); } } } else if (command == "update_user_index_result") // 사용되고 있음 { int index = N ["index"].AsInt; UXPlayerController player = UXPlayerController.Instance; player.SetIndex(index); if (OnIndexChanged != null) { UXLog.SetLogMessage(" onindexchanged"); OnIndexChanged(index); } } else if (command == "send_error") { } else if (command == "exit_result") { if (OnExit != null) { OnExit(); } } else if (command == "host_close") { if (OnHostDisconnected != null) { OnHostDisconnected(); } } else if (command == "data") { string val = N ["data"].Value.ToString(); if (val == "") { val = N ["data"].ToString(); } int senderCode = N ["sender"].AsInt; int userIndex = GetUserIndexFromCode(senderCode); if (OnReceived != null) { //OnReceived (userIndex, val); OnReceived(senderCode, val); } } else if (command == "check_network_state_result") //이거 안올듯. 위에서 cmd:check_network_state를안보내 { int cur = N ["count"].AsInt; string temp = N ["time"]; long stime = long.Parse(temp); networkCheckValues [cur - 1] = DateTime.Now.Ticks - stime; if (cur >= networkCheckCount) { float totalTime = 0; for (int i = 0; i < networkCheckCount; i++) { totalTime += networkCheckValues [i]; } if (OnNetworkReported != null) { OnNetworkReported(networkCheckCount, totalTime); } UXPlayerController player = UXPlayerController.Instance; if (isSendNetWorkResult == true) { string sendString = "{\"cmd\":\"report_network_state\",\"u_code\":\"" + player.GetCode() + "\",\"l_code\":\"" + launcherCode + "\",\"count\":\"" + networkCheckCount + "\",\"time\":\"" + totalTime + "\"}&"; Send(sendString); } } } else if (command == "start_game_result") { isGameStarted = true; if (OnGameStart != null) { OnGameStart(); } } else if (command == "restart_game_result") { isGameStarted = true; if (OnGameRestart != null) { OnGameRestart(); } } else if (command == "result_game_result") //안쓰일듯 { if (OnGameResult != null) { OnGameResult(); } } else if (command == "end_game_result") { isGameStarted = false; if (OnGameEnd != null) { OnGameEnd(); } } else if (command == "host_joined") { isHostJoined = true; if (OnHostJoined != null) { OnHostJoined(); } } else if (command == "get_user_list_result") { Debug.Log("UserList: "); List <UXUser> userList = ParseUserList((JSONArray)N ["user_list"]); UXUserController userController = UXUserController.Instance; if (userController.IsEqual(userList) == false) { userController.CopyList(userList); if (OnUserListReceived != null) { OnUserListReceived(userList); //log찍는듯 } } /* * if (connectMode == UXConnectController.Mode.Client) { //PAD면 * UXPlayerController playerController = UXPlayerController.Instance; * for (int i = 0; i < userController.GetCount (); i++) { * UXUser user = (UXUser)userController.GetAt (i); //유저마다 * if (playerController.GetCode () == user.GetCode ()) { //코드를 비교 해서 나를 찾는거 * if (i != playerController.GetIndex ()) { * if (OnIndexChanged != null) { * OnIndexChanged (i); * } * * playerController.SetIndex (i); * Debug.Log ("SetInedx : " + i); * } * break; * } * } * } */ } else if (command == "update_ready_count_result") { int ready = N ["ready"].AsInt; int total = N ["total"].AsInt; if (OnUpdateReadyCount != null) { OnUpdateReadyCount(ready, total); } } }
/** Test network speed and send the data to host * @param count sending count * @param sendResult True if want to broadcat the result, false otherwise */ public void NetworkTest(int count, bool sendResult = false) {//안쓰는듯 UXPlayerController player = UXPlayerController.Instance; isSendNetWorkResult = sendResult; networkCheckCount = count; networkCheckValues = new long[count]; for (int i = 0; i < count; i++) { string sendString = "{\"cmd\":\"check_network_state\",\"u_code\":\"" + player.GetCode() + "\",\"l_code\":\"" + launcherCode + "\",\"count\":\"" + (i + 1) + "\",\"time\":\"" + DateTime.Now.Ticks + "\"}" + DATA_DELIMITER; connect.Send(sendString); //{"cmd":"check_network_state","u_code":"player.GetCode()","l_code":"launcherCode","count":"(i+1)","time":"DataTime.Now.Ticks"}232 System.Threading.Thread.Sleep(50); } }
void Start() { Screen.orientation = ScreenOrientation.Portrait; Screen.SetResolution(720, 1280, true); //blackOut.SetActive(true); m_ClientController = UXClientController.Instance; m_PlayerController = UXPlayerController.Instance; PopupManager_RaS.IsFreeSetter(false); // TOOD : PopupManager 공통 모듈로 바꿔야함 userCode = m_PlayerController.GetCode(); // 유저 코드 가져옴 roomNumber = UXConnectController.GetRoomNumber(); // 방 번호 가져옴 //blackOut.SetActive(false); //userCode = m_PlayerController.GetCode (); //launcherCode = UXClientController.GetRoomNumber(); i_PlayerID = m_PlayerController.GetIndex(); m_ClientController.OnConnected += OnConnected; m_ClientController.OnConnectFailed += OnConnectFailed; m_ClientController.OnJoinSucceeded += OnJoinSucceeded; m_ClientController.OnJoinFailed += OnJoinFailed; m_ClientController.OnDisconnected += OnDisconnected; m_ClientController.OnUserAdded += OnUserAdded; m_ClientController.OnUserRemoved += OnUserRemoved; m_ClientController.OnUserLeavedInGame += OnUserLeaved; m_ClientController.OnNetworkReported += OnNetworkReported; m_ClientController.OnUpdateReadyCount += OnUpdateReadyCount; m_ClientController.OnGameStart += OnGameStart; m_ClientController.OnGameRestart += OnGameRestart; m_ClientController.OnGameResult += OnGameResult; m_ClientController.OnIndexChanged += OnIndexChanged; m_ClientController.OnUserListReceived += OnUserListReceived; m_ClientController.OnGameEnd += OnGameEnd; m_ClientController.OnExit += OnExit; m_ClientController.OnAckFailed += OnAckFailed; m_ClientController.OnHostDisconnected += OnHostDisconnected; //inapp.OnPurchaseSuccess += OnPurchaseSuccess; //========================================== m_ClientController.OnHostJoined += OnHostJoined; m_ClientController.OnError += OnError; m_ClientController.OnReceived += OnReceived; //========================================== if (m_ClientController.IsConnected() == false) { m_ClientController.Connect(); } else { //m_ClientController.Join("none"); m_ClientController.Join(GAME_PACKAGE_NAME); } cancelButton.SetActive(false); DontDestroyOnLoad(this.gameObject); }
void OnReceived(int userCode, string msg) { Debug.Log("OnReceived > userCode : " + userCode + ", msg : " + msg); string splitchar = ","; string[] words = null; msg.Trim(); words = msg.Split(splitchar.ToCharArray(), System.StringSplitOptions.None); if (words[0] == "Exit") { //PopupManager_RaS.Instance.CloseGame(); } /* * if (Application.loadedLevelName == "LobbyClient") { * switch(words[0]) * { * case "QROn": * GameObject.Find("QR_Back").GetComponent<QROnOff_ras>().SetQROnOff(true); * break; * case "QROff": * GameObject.Find("QR_Back").GetComponent<QROnOff_ras>().SetQROnOff(false); * break; * } * } */ GameObject phoneScreen = GameObject.Find("PS"); if (phoneScreen == null) { return; } switch (words[0]) { // Character Select case "SoldOut": phoneScreen.GetComponent <PS_CharacterSelectLobbyManager>().SetCharacterSoldOut(int.Parse(words[1])); break; case "StartTutorial": Application.LoadLevel("TutorialPS"); break; // Tutorial case "StartInGame": Application.LoadLevel("InGamePS"); break; // In Game case "DiamondSound": phoneScreen.GetComponent <PS_InGameManager>().PlayDiamondSound(int.Parse(words[1])); break; case "RingSound": phoneScreen.GetComponent <PS_InGameManager>().PlayRingSound(int.Parse(words[1])); break; case "GoldSound": phoneScreen.GetComponent <PS_InGameManager>().PlayGoldSound(int.Parse(words[1])); break; case "SilverSound": phoneScreen.GetComponent <PS_InGameManager>().PlaySilverSound(int.Parse(words[1])); break; case "AppleSound": phoneScreen.GetComponent <PS_InGameManager>().PlayAppleSound(int.Parse(words[1])); break; case "SellSound": phoneScreen.GetComponent <PS_InGameManager>().PlaySellSound(int.Parse(words[1])); break; case "SpecialSellSound": phoneScreen.GetComponent <PS_InGameManager>().PlaySpecialSellSound(int.Parse(words[1])); break; case "SpeedSound": phoneScreen.GetComponent <PS_InGameManager>().PlaySpeedSound(int.Parse(words[1])); break; case "MagnetSound": phoneScreen.GetComponent <PS_InGameManager>().PlayMagnetSound(int.Parse(words[1])); break; case "BonusSound": phoneScreen.GetComponent <PS_InGameManager>().PlayBonusSound(int.Parse(words[1])); break; case "StealEmojiSound": phoneScreen.GetComponent <PS_InGameManager>().PlayStealEmojiSound(); break; case "AngryEmojiSound": phoneScreen.GetComponent <PS_InGameManager>().PlayAngryEmojiSound(); break; case "CrashEmojiSound": phoneScreen.GetComponent <PS_InGameManager>().PlayCrashEmojiSound(); break; case "MyScore": myScore = System.Convert.ToInt32(words[1]); break; case "StartResult": if (m_PlayerController.GetCode() == System.Convert.ToInt32(words[1])) { isRoomMaster = true; } Application.LoadLevel("ResultPS"); break; case "Pause_cli": GameObject.Find("PauseButton").GetComponent <PauseManager_ras>().GetPause(); break; case "Resume_cli": GameObject.Find("PauseButton").GetComponent <PauseManager_ras>().GetResume(); break; // Result case "MyRank": myRank = System.Convert.ToInt32(words[1]); break; case "Replay": m_ClientController.SendEndGame(); m_ClientController.SetPlayerState(UXUser.LobbyState.Wait); Application.LoadLevel("LobbyClient"); break; case "CancelSoldOut": int charType = int.Parse(words [1]); phoneScreen.GetComponent <PS_CharacterSelectLobbyManager>().CancelCharacterSoldOut(charType); break; } }