Commit c1a1e4fb authored by IceYGO's avatar IceYGO

Use the latest YGOSharp.Network to improve performances

parent 2241def4
using OCGWrapper; using OCGWrapper;
using OCGWrapper.Enums; using OCGWrapper.Enums;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using YGOSharp.Network; using YGOSharp.Network;
namespace WindBot.Game namespace WindBot.Game
...@@ -54,7 +55,7 @@ namespace WindBot.Game ...@@ -54,7 +55,7 @@ namespace WindBot.Game
Name = Data.Name; Name = Data.Name;
} }
public void Update(GamePacketReader packet, Duel duel) public void Update(BinaryReader packet, Duel duel)
{ {
int flag = packet.ReadInt32(); int flag = packet.ReadInt32();
if ((flag & (int)Query.Code) != 0) if ((flag & (int)Query.Code) != 0)
......
using OCGWrapper.Enums; using OCGWrapper.Enums;
using System.Collections.Generic; using System.Collections.Generic;
using WindBot.Game.AI; using WindBot.Game.AI;
using YGOSharp.Network;
namespace WindBot.Game namespace WindBot.Game
{ {
public class GameAI public class GameAI
{ {
public GameClient Game { get; private set; } public GameClient Game { get; private set; }
public CoreClient Connection { get; private set; }
public Duel Duel { get; private set; } public Duel Duel { get; private set; }
public Executor Executor { get; set; } public Executor Executor { get; set; }
public AIFunctions Utils { get; private set; } public AIFunctions Utils { get; private set; }
...@@ -18,7 +16,6 @@ namespace WindBot.Game ...@@ -18,7 +16,6 @@ namespace WindBot.Game
public GameAI(GameClient game, Duel duel) public GameAI(GameClient game, Duel duel)
{ {
Game = game; Game = game;
Connection = game.Connection;
Duel = duel; Duel = duel;
Utils = new AIFunctions(duel); Utils = new AIFunctions(duel);
......
This diff is collapsed.
using System.Text; using System.IO;
using System.Net;
using System.Text;
using YGOSharp.Network; using YGOSharp.Network;
using YGOSharp.Network.Enums; using YGOSharp.Network.Enums;
using YGOSharp.Network.Utils;
namespace WindBot.Game namespace WindBot.Game
{ {
public class GameClient public class GameClient
{ {
public CoreClient Connection { get; private set; } public YGOClient Connection { get; private set; }
public string Username; public string Username;
public string Deck; public string Deck;
...@@ -27,40 +30,45 @@ namespace WindBot.Game ...@@ -27,40 +30,45 @@ namespace WindBot.Game
public void Start() public void Start()
{ {
Connection = new CoreClient(_serverHost, _serverPort); Connection = new YGOClient();
Connection.MessageReceived += OnMessageReceived;
_behavior = new GameBehavior(this); _behavior = new GameBehavior(this);
GamePacketWriter packet = new GamePacketWriter(CtosMessage.PlayerInfo); Connection.Connected += OnConnected;
packet.Write(Username, 20); Connection.PacketReceived += OnPacketReceived;
Connection.Connect(IPAddress.Parse(_serverHost), _serverPort);
}
private void OnConnected()
{
BinaryWriter packet = GamePacketFactory.Create(CtosMessage.PlayerInfo);
packet.WriteUnicode(Username, Program.PlayerNameSize);
Connection.Send(packet); Connection.Send(packet);
byte[] junk = { 0xCC, 0xCC, 0x00, 0x00, 0x00, 0x00 }; byte[] junk = { 0xCC, 0xCC, 0x00, 0x00, 0x00, 0x00 };
packet = new GamePacketWriter(CtosMessage.JoinGame); packet = GamePacketFactory.Create(CtosMessage.JoinGame);
packet.Write(Program.ProVersion); packet.Write(Program.ProVersion);
packet.Write(junk); packet.Write(junk);
packet.Write(_roomInfos, 30); packet.WriteUnicode(_roomInfos, 30);
Connection.Send(packet); Connection.Send(packet);
} }
public void Tick() public void Tick()
{ {
Connection.UpdateNetwork();
Connection.Update(); Connection.Update();
} }
public void Chat(string message) public void Chat(string message)
{ {
byte[] content = Encoding.Unicode.GetBytes(message + "\0"); byte[] content = Encoding.Unicode.GetBytes(message + "\0");
GamePacketWriter chat = new GamePacketWriter(CtosMessage.Chat); BinaryWriter chat = GamePacketFactory.Create(CtosMessage.Chat);
chat.Write(content); chat.Write(content);
Connection.Send(chat); Connection.Send(chat);
} }
private void OnMessageReceived(object sender, MessageEventArgs e) private void OnPacketReceived(BinaryReader reader)
{ {
_behavior.OnPacket(e.Message); _behavior.OnPacket(reader);
} }
} }
} }
\ No newline at end of file
using System.IO;
using YGOSharp.Network.Enums;
namespace WindBot.Game
{
public class GamePacketFactory
{
public static BinaryWriter Create(CtosMessage message)
{
BinaryWriter writer = new BinaryWriter(new MemoryStream());
writer.Write((byte)message);
return writer;
}
}
}
...@@ -9,7 +9,8 @@ namespace WindBot ...@@ -9,7 +9,8 @@ namespace WindBot
{ {
public class Program public class Program
{ {
public const short ProVersion = 0x1338; public static short ProVersion = 0x1330;
public static int PlayerNameSize = 20;
internal static Random Rand; internal static Random Rand;
......
...@@ -31,6 +31,9 @@ ...@@ -31,6 +31,9 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Mono.Data.Sqlite"> <Reference Include="Mono.Data.Sqlite">
<HintPath>.\Mono.Data.Sqlite.dll</HintPath> <HintPath>.\Mono.Data.Sqlite.dll</HintPath>
...@@ -80,6 +83,7 @@ ...@@ -80,6 +83,7 @@
<Compile Include="Game\GameAI.cs" /> <Compile Include="Game\GameAI.cs" />
<Compile Include="Game\GameBehavior.cs" /> <Compile Include="Game\GameBehavior.cs" />
<Compile Include="Game\GameClient.cs" /> <Compile Include="Game\GameClient.cs" />
<Compile Include="Game\GamePacketFactory.cs" />
<Compile Include="Game\MainPhase.cs" /> <Compile Include="Game\MainPhase.cs" />
<Compile Include="Game\MainPhaseAction.cs" /> <Compile Include="Game\MainPhaseAction.cs" />
<Compile Include="Game\Room.cs" /> <Compile Include="Game\Room.cs" />
......
No preview for this file type
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