Skip to content
Snippets Groups Projects
Commit f69e5da3 authored by Sillinger Péter's avatar Sillinger Péter
Browse files

Room related issues rectified.

parent 510d708d
No related branches found
No related tags found
No related merge requests found
......@@ -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
{
if (client.roomID == null)
{
//TODO: belépni a szobába
client.CreateRoom();
}
else
{
(sender as GameClient).remoteServer.LeaveRoom(roomID);
client.LeaveCurrentRoom();
}
}
catch (ServerErrorException ex)
{
HandleServerError(this, ex.Message);
}
}
......@@ -482,11 +492,22 @@ namespace zsirozas
{
int idx = (sender as ListBox).IndexFromPoint(e.Location);
//todo akarom-e a klienst lock-olni?
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);
}
}
......
......@@ -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)
{
......
......@@ -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)
{
......
......@@ -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;
}
}
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment