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); } } }