diff --git a/zsirozas/Form1.cs b/zsirozas/Form1.cs index 0f9e320e487670529d04c6cabd0702d1b42fe9a0..d1d913defe03f5720993de1c127123251ae261b2 100644 --- a/zsirozas/Form1.cs +++ b/zsirozas/Form1.cs @@ -333,7 +333,8 @@ namespace zsirozas { try { - //client.remoteServer.RemoveUser(client.userID); //todo visszarakni amint nem fedi el a többi hibát + client.LeaveCurrentRoom(); + //TODO: logout? } catch (Exception) { @@ -375,7 +376,10 @@ namespace zsirozas { var info = infos[(sender as ListBox).Items[idx].ToString()]; bool joined = InfoDialog.ShowRoomInfo(info, client.roomID); - //TODO: be is lépni + if (joined) + { + client.JoinRoom(info.roomID); + } } } private void listBoxUsers_DrawItem(object sender, DrawItemEventArgs e) @@ -467,14 +471,20 @@ namespace zsirozas private void buttonCreateRoom_Click(object sender, EventArgs e) { - string roomID = (sender as GameClient).roomID; - if (roomID == null) + try { - //TODO: belépni a szobába + if (client.roomID == null) + { + client.CreateRoom(); + } + else + { + client.LeaveCurrentRoom(); + } } - else + catch (ServerErrorException ex) { - (sender as GameClient).remoteServer.LeaveRoom(roomID); + HandleServerError(this, ex.Message); } } @@ -482,12 +492,23 @@ namespace zsirozas { int idx = (sender as ListBox).IndexFromPoint(e.Location); //todo akarom-e a klienst lock-olni? - lock (client) if (idx != ListBox.NoMatches) - { - var info = client.remoteServer.UserInfo((sender as ListBox).Items[idx].ToString()); - bool kickedOut = InfoDialog.ShowUserInfo(info, !info.occupied && info.roomID == null && info.userID != client.userID && client.roomID != null, "KickOut"); - //TODO: ki is rúgni - } + try + { + lock (client) if (idx != ListBox.NoMatches) + { + var info = client.remoteServer.UserInfo((sender as ListBox).Items[idx].ToString()); + bool kickedOut = InfoDialog.ShowUserInfo(info, !info.occupied && info.roomID == null && info.userID != client.userID && client.roomID != null, "KickOut"); + //TODO: ki is rúgni + if (kickedOut) + { + client.remoteServer.LeaveRoom(info.userID); + } + } + } + catch (ServerErrorException ex) + { + HandleServerError(this, ex.Message); + } } private void buttonUseSignalR_Click(object sender, EventArgs e) diff --git a/zsirozas/GameClient.cs b/zsirozas/GameClient.cs index 0c192bff370103991088af43b89f439672e6d884..7132cd71ec4c0afa9941e976204e2dc92e0a3c4f 100644 --- a/zsirozas/GameClient.cs +++ b/zsirozas/GameClient.cs @@ -118,6 +118,16 @@ namespace zsirozas remoteServer.JoinRoom(userID, roomID); } + public void LeaveCurrentRoom() + { + remoteServer.LeaveRoom(userID); + roomID = null; + } + + public void CreateRoom() + { + roomID = remoteServer.CreateRoom(userID); + } public void SimpleNotify(ServerEvent @event, string param0) { diff --git a/zsirozas/GameServer.cs b/zsirozas/GameServer.cs index b3a6d382ab049903d1a14c6c0204b8bf459fcfd1..0d007113ee7bd629e69213423186b643844c72c1 100644 --- a/zsirozas/GameServer.cs +++ b/zsirozas/GameServer.cs @@ -330,6 +330,10 @@ namespace zsirozas catch (GameOverException ex) { Console.WriteLine("[LOG] Game " + ex.Message + "ended."); + + //TODO: occupioed állítás? + RoomsByID[UsersByID[GamesByID[ex.Message].playersByOrder[0]].roomID].gameID = null; + GamesByID.Remove(ex.Message); Games.Remove(ex.Message); if (this.oneShot) @@ -366,6 +370,7 @@ namespace zsirozas Rooms.Add(r.roomID); UsersByID[userID].roomID = r.roomID; Console.WriteLine("[LOG] Room " + r.roomID + " has been created."); + UsersByID[userID].client.SimpleNotify(ServerEvent.RoomChanged, r.roomID); return r.roomID; } else throw new InvalidActionException("This user is already in a room. Leve the room to create a new one."); @@ -440,6 +445,7 @@ namespace zsirozas if (Rooms.Contains(UsersByID[userID].roomID)) { RoomsByID[UsersByID[userID].roomID].userList.Remove(userID); + UsersByID[userID].client.SimpleNotify(ServerEvent.RoomChanged, null); Console.WriteLine("[LOG] " + userID + " left room " + UsersByID[userID].roomID); if (!bigRoom && RoomsByID[UsersByID[userID].roomID].userList.Count == 0) { diff --git a/zsirozas/InfoDialog.cs b/zsirozas/InfoDialog.cs index 4cbca574c2c2455f4fcea94299df27f716894746..d2752c70bf1c69e0ea444166fc2bdaa2feb20580 100644 --- a/zsirozas/InfoDialog.cs +++ b/zsirozas/InfoDialog.cs @@ -28,6 +28,7 @@ namespace zsirozas dialog.Height -= dialog.listBox1.Height; dialog.buttonOK.Text = redefineOKButtonText; dialog.buttonOK.Enabled = invitable; + dialog.buttonOK.Click += (sender, e) => { dialog.DialogResult = DialogResult.OK; }; return dialog.ShowDialog() == DialogResult.OK; } } @@ -42,6 +43,7 @@ namespace zsirozas dialog.listBox1.Items.AddRange(room.players); dialog.buttonOK.Text = "Join"; dialog.buttonOK.Enabled = (room.gameID == null) && ownRoom == null; + dialog.buttonOK.Click += (sender, e) => { dialog.DialogResult = DialogResult.OK; }; return dialog.ShowDialog() == DialogResult.OK; } } diff --git a/zsirozas/RawTcpTransport.cs b/zsirozas/RawTcpTransport.cs index af84a8a9dceb118f8e163aed0d2173e1b2b50b1b..2685e0eb54bb64ab8d05abb43a0c276bd43ead87 100644 --- a/zsirozas/RawTcpTransport.cs +++ b/zsirozas/RawTcpTransport.cs @@ -59,7 +59,7 @@ namespace zsirozas public bool ValidateConnection(object connInfo) { - return (msgConn.Client.RemoteEndPoint != null) && ((connInfo is IPAddress) && (IPAddress)connInfo == ((IPEndPoint)msgConn.Client.RemoteEndPoint).Address); + return (msgConn.Client.RemoteEndPoint != null) && ((connInfo is IPAddress) && ((IPAddress)connInfo).Equals(((IPEndPoint)msgConn.Client.RemoteEndPoint).Address)); } public void ParseNextMessage(StreamReader sr)