Commit c1a1e4fb authored by IceYGO's avatar IceYGO

Use the latest YGOSharp.Network to improve performances

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