bool CheckUserState() { UXUserController users = UXUserController.Instance; int connectedUser = 0; for (int i = 0; i < users.GetCount(); i++) { UXUser user = (UXUser)users.GetAt(i); UXUser.LobbyState userState = user.GetLobbyState(); if (userState == UXUser.LobbyState.Ready) { connectedUser++; } else if (userState == UXUser.LobbyState.Wait) { return(false); } } if (connectedUser >= autoStartMinimumUser) //왜 너랑? { return(true); } return(false); }
void Update() { if (hostController != null) { hostController.Run(); } if (isGameStart == false) { maxPlayer = hostController.GetMaxUser(); for (int i = 0; i < 6; i++) { if (i < playerCount) { if (playerNumber[i].activeSelf == false) { playerNumber[i].SetActive(true); Camera.main.GetComponent <AudioSource>().PlayOneShot(numberSound); } UXUserController userController = UXUserController.Instance; UXUser user = (UXUser)userController.GetAt(i); if (user.GetLobbyState() == UXUser.LobbyState.Ready) { playerNumber[i].GetComponentInChildren <SpriteRenderer>().sprite = playerNumberOn[i]; connectedUser[i] = true; } else { playerNumber[i].GetComponentInChildren <SpriteRenderer>().sprite = playerNumberOff[i]; connectedUser[i] = false; } } else { playerNumber[i].SetActive(false); } } } if (Input.GetKeyDown(KeyCode.Escape) == true) { // PopupManager.Instance().OpenPopup(POPUP_TYPE.POPUP_EXITCONFIRM); } /* * if(freeLabel != null) { * if (UXHostController.room.IsPremium) { * freeLabel.SetActive (false); * } else { * freeLabel.SetActive (true); * } * } */ }
public void CopyGameUserList() { UXUserController userList = UXUserController.Instance; GameUserList.Clear(); foreach (UXObject obj in userList.GetList()) { UXUser user = (UXUser)obj; GameUserList.Add(user.GetCode()); } }
void OnLobbyStateChanged(int idx, UXUser.LobbyState state) { if (OnUserLobbyStateChanged != null) { OnUserLobbyStateChanged(idx, state); } bool isAllReady = true; UXUserController users = UXUserController.Instance; int connectedUser = 0; for (int i = 0; i < users.GetCount(); i++) { UXUser user = (UXUser)users.GetAt(i); UXUser.LobbyState userState = user.GetLobbyState(); if (userState == UXUser.LobbyState.Ready) { connectedUser++; } else if (userState == UXUser.LobbyState.Wait) { isAllReady = false; break; } } SendUpdateReadyCount(connectedUser, users.GetCount()); if (/*autoStartStarted == true &&*/ isAllReady == false) { autoStartCount = 0; autoStartStarted = false; isStartSended = false; //if (startGameTimer != null) { // startGameTimer.Dispose(); //} //OnAutoStartFailed(); } if (isAllReady == true && autoStartStarted == false) { if (isAutoStart == true && connectedUser >= autoStartMinimumUser) { autoStartCount = 0; autoStartStarted = true; isStartSended = false; ClearTimer(); startGameTimer = new System.Threading.Timer(CountAutoStart, null, 1000, 1000); } } }
/** Return user's ready state * @param user index * @return True if user is ready, false otherwise */ public bool IsReadyUser(int index) { UXUserController users = UXUserController.Instance; if (index < 0 || index >= users.GetCount()) //인덱스는 0,1,2,3인가봐 { return(false); } UXUser user = (UXUser)users.GetAt(index); return(user.GetLobbyState() == UXUser.LobbyState.Ready); }
/** Return user index from user code * @param code user code * @return User index. if it can't be found then return -1 */ public int GetUserIndexFromCode(int code) { UXUserController userController = UXUserController.Instance; for (int i = 0; i < userController.GetCount(); i++) { UXUser user = (UXUser)userController.GetAt(i); if (code == user.GetCode()) { return(i);//user index로 사용됨 index = GetUserIndexFromCode()이케//index : 0,1,2,3 +1 = 1,2,3,4P } } return(-1); }
/** Return connnected user's number * @return user number */ public int GetConnectUserCount() { UXUserController users = UXUserController.Instance; return(users.GetCount()); }
void ProcessReceivedMessage(string data) { if (string.IsNullOrEmpty(data) == true || data.Length <= 0) //data가 없는 경우는 ㅂㅂ { return; } var N = JSON.Parse(data); string command = N["cmd"]; if (command == "join_result") { int result = N ["ack"].AsInt; if (result != UXRoomConnect.ACK_RESULT_OK) { int errCode = ProcessConnectError(result); if (OnJoinFailed != null) { OnJoinFailed(errCode); } return; } isJoined = true; isHostJoined = true; JSONArray users = (JSONArray)N ["user_list"]; if (users.Count > 0) { List <UXUser> list = ParseUserList((JSONArray)users); for (int i = 0; i < list.Count; i++) { UXUser u = list [i]; u.SetConnected(true); //isConnected = ture;로 //u.GetProfileFromServer (); //host면 x ,pad면 name, image url (정보가져오기) } UXUserController.Instance.CopyList(list); } if (OnJoinSucceeded != null) { OnJoinSucceeded(isHostJoined); } } else if (command == "change_lobby_state_result") { int code = N ["u_code"].AsInt; string stateString = N ["state"]; Debug.Log(code); int userIndex = GetUserIndexFromCode(code); UXUser.LobbyState state = UXUser.LobbyState.Wait; if (stateString == "ready") { state = UXUser.LobbyState.Ready; } UXUser userObj = (UXUser)UXUserController.Instance.GetAt(userIndex); userObj.SetLobbyState(state); OnLobbyStateChanged(userIndex, state); } else if (command == "report_network_state_result") //이것들도 안쓰이겠찌이 { int count = N ["count"].AsInt; string temp = N ["time"]; float totalTime = float.Parse(temp); int code = N ["u_code"].AsInt; int userIndex = GetUserIndexFromCode(code); UXUser userObj = (UXUser)UXUserController.Instance.GetAt(userIndex); float time = totalTime / ((float)count * 10000000.0f); userObj.SetNetworkSpeed(time); if (OnUserNetworkReported != null) { OnUserNetworkReported(userIndex, count, time); } } else if (command == "premium_user_result") { int code = N ["u_code"].AsInt; UXUserController userList = UXUserController.Instance; for (int i = 0; i < userList.GetCount(); i++) { UXUser user = (UXUser)userList.GetAt(i); if (user.GetCode() == code) { user.IsPremium = true; break; } } if (OnJoinPremiumUser != null) { OnJoinPremiumUser(); } } else if (command == "user_del") { int code = N ["u_code"].AsInt; UXUserController userList = UXUserController.Instance; UXUser user = userList.GetUserByCode(code); if (user.IsPremium) { if (OnLeavePremiumUser != null) { OnLeavePremiumUser(); } } base.ProcessReceivedMessage(data); } else { base.ProcessReceivedMessage(data); } }
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); } } }