Commit bb40ca78 authored by IceYGO's avatar IceYGO

Store the room position instead of comparing the username

parent 8efd8d09
...@@ -134,6 +134,7 @@ namespace WindBot.Game ...@@ -134,6 +134,7 @@ namespace WindBot.Game
Connection.Close(); Connection.Close();
return; return;
} }
_room.Position = pos;
_room.IsHost = ((type >> 4) & 0xF) != 0; _room.IsHost = ((type >> 4) & 0xF) != 0;
_room.IsReady[pos] = true; _room.IsReady[pos] = true;
Connection.Send(CtosMessage.HsReady); Connection.Send(CtosMessage.HsReady);
...@@ -202,7 +203,7 @@ namespace WindBot.Game ...@@ -202,7 +203,7 @@ namespace WindBot.Game
if (!Directory.Exists(directory)) if (!Directory.Exists(directory))
Directory.CreateDirectory(directory); Directory.CreateDirectory(directory);
string otherName = _room.Names[0] == Game.Username ? _room.Names[1] : _room.Names[0]; string otherName = _room.Position == 0 ? _room.Names[1] : _room.Names[0];
string file = DateTime.Now.ToString("yyyy-MM-dd.HH-mm.") + otherName + ".yrp"; string file = DateTime.Now.ToString("yyyy-MM-dd.HH-mm.") + otherName + ".yrp";
string fullname = Path.Combine(directory, file); string fullname = Path.Combine(directory, file);
...@@ -235,11 +236,7 @@ namespace WindBot.Game ...@@ -235,11 +236,7 @@ namespace WindBot.Game
deck = packet.ReadInt16(); deck = packet.ReadInt16();
extra = packet.ReadInt16(); extra = packet.ReadInt16();
_duel.Fields[GetLocalPlayer(1)].Init(deck, extra); _duel.Fields[GetLocalPlayer(1)].Init(deck, extra);
if (_room.Names[0] != Game.Username && _room.Names[1] != Game.Username)
{
Connection.Close();
return;
}
Logger.WriteLine("Duel started: " + _room.Names[0] + " versus " + _room.Names[1]); Logger.WriteLine("Duel started: " + _room.Names[0] + " versus " + _room.Names[1]);
_ai.OnStart(); _ai.OnStart();
} }
...@@ -248,7 +245,7 @@ namespace WindBot.Game ...@@ -248,7 +245,7 @@ namespace WindBot.Game
{ {
int result = GetLocalPlayer(packet.ReadByte()); int result = GetLocalPlayer(packet.ReadByte());
string otherName = _room.Names[0] == Game.Username ? _room.Names[1] : _room.Names[0]; string otherName = _room.Position == 0 ? _room.Names[1] : _room.Names[0];
string textResult = (result == 2 ? "Draw" : result == 0 ? "Win" : "Lose"); string textResult = (result == 2 ? "Draw" : result == 0 ? "Win" : "Lose");
Logger.WriteLine("Duel finished against " + otherName + ", result: " + textResult); Logger.WriteLine("Duel finished against " + otherName + ", result: " + textResult);
} }
...@@ -442,7 +439,7 @@ namespace WindBot.Game ...@@ -442,7 +439,7 @@ namespace WindBot.Game
foreach (ClientCard card in cards) foreach (ClientCard card in cards)
{ {
int len = packet.ReadInt32(); int len = packet.ReadInt32();
if (len < 8) continue; if (len == 4) continue;
long pos = packet.Position; long pos = packet.Position;
card.Update(packet, _duel); card.Update(packet, _duel);
packet.Position = pos + len - 4; packet.Position = pos + len - 4;
......
...@@ -5,11 +5,13 @@ ...@@ -5,11 +5,13 @@
public bool IsHost { get; set; } public bool IsHost { get; set; }
public string[] Names { get; set; } public string[] Names { get; set; }
public bool[] IsReady { get; set; } public bool[] IsReady { get; set; }
public int Position { get; set; }
public Room() public Room()
{ {
Names = new string[8]; Names = new string[8];
IsReady = new bool[8]; IsReady = new bool[8];
Position = -1;
} }
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment