static public void LeaveRoomHandler(NetConnection connection, object data) { if (!PlayerCaches.AuthDone(connection)) { return; } if (PlayerCaches.InLobby(connection)) { return; } int roomid = PlayerCaches.GetRoomID(connection); if (Lobby.GetRoomState(roomid) == 1) { return; } Lobby.LeaveRoom(connection, roomid); Lobby.SendRoomStateToAll(roomid); Lobby.CheckBattleStart(roomid); GSrv.Send(MessageType.ReplySuccessLeaveRoom, connection, NetDeliveryMethod.ReliableOrdered); LobbyState state = Lobby.GetLobbyState(); GSrv.Send(MessageType.ReplyLobbyState, GSrv.Serialize <LobbyState>(state), connection, NetDeliveryMethod.ReliableOrdered); }
public static LobbyState GetLobbyState() { LobbyState state = new LobbyState(); foreach (Room room in rooms) { state.summaries.Add(room.GetRoomSummary()); } return(state); }
void RefreshLobbyUI(LobbyState state) { //delete foreach (GameObject room in roomSummaryUIs) { Destroy(room); } roomSummaryUIs.Clear(); //UI for (int i = 0; i < state.summaries.Count; i++) { GameObject room = GameObject.Instantiate(Resources.Load("RoomSummary"), lobby.transform) as GameObject; room.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 142 + -34 * i); room.GetComponent <RoomSummaryScript>().Init(state.summaries[i]); roomSummaryUIs.Add(room); } }
static public void SendUserNameHandler(NetConnection connection, object data) { string username = (string)data; if (username == "") { username = "******"; } if (PlayerCaches.AuthDone(connection)) { return; } Console.WriteLine("Enter:" + username); int userid = Lobby.AddPlayer(connection, username); GSrv.Send(MessageType.ReplyUserID, userid, connection, NetDeliveryMethod.ReliableOrdered); LobbyState state = Lobby.GetLobbyState(); GSrv.Send(MessageType.ReplyLobbyState, GSrv.Serialize <LobbyState>(state), connection, NetDeliveryMethod.ReliableOrdered); }
static public void RequestLobbyStateHandler(NetConnection connection, object data) { LobbyState state = Lobby.GetLobbyState(); GSrv.Send(MessageType.ReplyLobbyState, GSrv.Serialize <LobbyState>(state), connection, NetDeliveryMethod.ReliableOrdered); }
public void ReplyLobbyStateHandler(NetConnection connection, object data) { LobbyState state = GCli.Deserialize <LobbyState>((byte[])data); RefreshLobbyUI(state); }