Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
W
windbot
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tang Xinwei
windbot
Commits
c1a1e4fb
Commit
c1a1e4fb
authored
Jun 18, 2016
by
IceYGO
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use the latest YGOSharp.Network to improve performances
parent
2241def4
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
108 additions
and
81 deletions
+108
-81
Game/ClientCard.cs
Game/ClientCard.cs
+2
-1
Game/GameAI.cs
Game/GameAI.cs
+0
-3
Game/GameBehavior.cs
Game/GameBehavior.cs
+64
-63
Game/GameClient.cs
Game/GameClient.cs
+21
-13
Game/GamePacketFactory.cs
Game/GamePacketFactory.cs
+15
-0
Program.cs
Program.cs
+2
-1
WindBot.csproj
WindBot.csproj
+4
-0
YGOSharp.Network.dll
YGOSharp.Network.dll
+0
-0
No files found.
Game/ClientCard.cs
View file @
c1a1e4fb
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
(
GamePacket
Reader
packet
,
Duel
duel
)
public
void
Update
(
Binary
Reader
packet
,
Duel
duel
)
{
int
flag
=
packet
.
ReadInt32
();
if
((
flag
&
(
int
)
Query
.
Code
)
!=
0
)
...
...
Game/GameAI.cs
View file @
c1a1e4fb
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
);
...
...
Game/GameBehavior.cs
View file @
c1a1e4fb
...
...
@@ -7,19 +7,20 @@ using System.Text.RegularExpressions;
using
WindBot.Game.AI
;
using
YGOSharp.Network
;
using
YGOSharp.Network.Enums
;
using
YGOSharp.Network.Utils
;
namespace
WindBot.Game
{
public
class
GameBehavior
{
public
GameClient
Game
{
get
;
private
set
;
}
public
Core
Client
Connection
{
get
;
private
set
;
}
public
YGO
Client
Connection
{
get
;
private
set
;
}
public
Deck
Deck
{
get
;
private
set
;
}
private
GameAI
_ai
;
private
IDictionary
<
StocMessage
,
Action
<
GamePacket
Reader
>>
_packets
;
private
IDictionary
<
GameMessage
,
Action
<
GamePacket
Reader
>>
_messages
;
private
IDictionary
<
StocMessage
,
Action
<
Binary
Reader
>>
_packets
;
private
IDictionary
<
GameMessage
,
Action
<
Binary
Reader
>>
_messages
;
private
Room
_room
;
private
Duel
_duel
;
...
...
@@ -29,8 +30,8 @@ namespace WindBot.Game
Game
=
game
;
Connection
=
game
.
Connection
;
_packets
=
new
Dictionary
<
StocMessage
,
Action
<
GamePacket
Reader
>>();
_messages
=
new
Dictionary
<
GameMessage
,
Action
<
GamePacket
Reader
>>();
_packets
=
new
Dictionary
<
StocMessage
,
Action
<
Binary
Reader
>>();
_messages
=
new
Dictionary
<
GameMessage
,
Action
<
Binary
Reader
>>();
RegisterPackets
();
_room
=
new
Room
();
...
...
@@ -46,12 +47,12 @@ namespace WindBot.Game
return
_duel
.
IsFirst
?
player
:
1
-
player
;
}
public
void
OnPacket
(
GamePacket
Reader
packet
)
public
void
OnPacket
(
Binary
Reader
packet
)
{
StocMessage
id
=
packet
.
ReadStoc
();
StocMessage
id
=
(
StocMessage
)
packet
.
ReadByte
();
if
(
id
==
StocMessage
.
GameMsg
)
{
GameMessage
msg
=
(
GameMessage
)
packet
.
ReadByte
();
GameMessage
msg
=
(
GameMessage
)
packet
.
ReadByte
();
if
(
_messages
.
ContainsKey
(
msg
))
_messages
[
msg
](
packet
);
return
;
...
...
@@ -111,9 +112,9 @@ namespace WindBot.Game
_messages
.
Add
(
GameMessage
.
AnnounceRace
,
OnAnnounceRace
);
}
private
void
OnJoinGame
(
GamePacket
Reader
packet
)
private
void
OnJoinGame
(
Binary
Reader
packet
)
{
GamePacketWriter
deck
=
new
GamePacketWriter
(
CtosMessage
.
UpdateDeck
);
BinaryWriter
deck
=
GamePacketFactory
.
Create
(
CtosMessage
.
UpdateDeck
);
deck
.
Write
(
Deck
.
Cards
.
Count
+
Deck
.
ExtraCards
.
Count
);
deck
.
Write
(
Deck
.
SideCards
.
Count
);
foreach
(
NamedCard
card
in
Deck
.
Cards
)
...
...
@@ -125,7 +126,7 @@ namespace WindBot.Game
Connection
.
Send
(
deck
);
}
private
void
OnTypeChange
(
GamePacket
Reader
packet
)
private
void
OnTypeChange
(
Binary
Reader
packet
)
{
int
type
=
packet
.
ReadByte
();
int
pos
=
type
&
0xF
;
...
...
@@ -140,15 +141,15 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
HsReady
);
}
private
void
OnPlayerEnter
(
GamePacket
Reader
packet
)
private
void
OnPlayerEnter
(
Binary
Reader
packet
)
{
string
name
=
packet
.
ReadUnicode
(
20
);
string
name
=
packet
.
ReadUnicode
(
Program
.
PlayerNameSize
);
int
pos
=
packet
.
ReadByte
();
if
(
pos
<
8
)
_room
.
Names
[
pos
]
=
name
;
}
private
void
OnPlayerChange
(
GamePacket
Reader
packet
)
private
void
OnPlayerChange
(
Binary
Reader
packet
)
{
int
change
=
packet
.
ReadByte
();
int
pos
=
(
change
>>
4
)
&
0xF
;
...
...
@@ -177,25 +178,25 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
HsStart
);
}
private
void
OnSelectHand
(
GamePacket
Reader
packet
)
private
void
OnSelectHand
(
Binary
Reader
packet
)
{
Connection
.
Send
(
CtosMessage
.
HandResult
,
(
byte
)
Program
.
Rand
.
Next
(
1
,
4
));
}
private
void
OnSelectTp
(
GamePacket
Reader
packet
)
private
void
OnSelectTp
(
Binary
Reader
packet
)
{
bool
start
=
_ai
.
OnSelectHand
();
Connection
.
Send
(
CtosMessage
.
TpResult
,
(
byte
)(
start
?
1
:
0
));
}
private
void
OnTimeLimit
(
GamePacket
Reader
packet
)
private
void
OnTimeLimit
(
Binary
Reader
packet
)
{
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
if
(
player
==
0
)
Connection
.
Send
(
CtosMessage
.
TimeConfirm
);
}
private
void
OnReplay
(
GamePacket
Reader
packet
)
private
void
OnReplay
(
Binary
Reader
packet
)
{
byte
[]
replay
=
packet
.
ReadToEnd
();
...
...
@@ -213,18 +214,18 @@ namespace WindBot.Game
Connection
.
Close
();
}
private
void
OnDuelEnd
(
GamePacket
Reader
packet
)
private
void
OnDuelEnd
(
Binary
Reader
packet
)
{
Connection
.
Close
();
}
private
void
OnChat
(
GamePacket
Reader
packet
)
private
void
OnChat
(
Binary
Reader
packet
)
{
packet
.
ReadInt16
();
// player
packet
.
ReadUnicode
(
256
);
// message
}
private
void
OnStart
(
GamePacket
Reader
packet
)
private
void
OnStart
(
Binary
Reader
packet
)
{
int
type
=
packet
.
ReadByte
();
_duel
.
IsFirst
=
(
type
&
0xF
)
==
0
;
...
...
@@ -241,7 +242,7 @@ namespace WindBot.Game
_ai
.
OnStart
();
}
private
void
OnWin
(
GamePacket
Reader
packet
)
private
void
OnWin
(
Binary
Reader
packet
)
{
int
result
=
GetLocalPlayer
(
packet
.
ReadByte
());
...
...
@@ -250,7 +251,7 @@ namespace WindBot.Game
Logger
.
WriteLine
(
"Duel finished against "
+
otherName
+
", result: "
+
textResult
);
}
private
void
OnDraw
(
GamePacket
Reader
packet
)
private
void
OnDraw
(
Binary
Reader
packet
)
{
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
int
count
=
packet
.
ReadByte
();
...
...
@@ -262,14 +263,14 @@ namespace WindBot.Game
}
}
private
void
OnShuffleDeck
(
GamePacket
Reader
packet
)
private
void
OnShuffleDeck
(
Binary
Reader
packet
)
{
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
foreach
(
ClientCard
card
in
_duel
.
Fields
[
player
].
Deck
)
card
.
SetId
(
0
);
}
private
void
OnShuffleHand
(
GamePacket
Reader
packet
)
private
void
OnShuffleHand
(
Binary
Reader
packet
)
{
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
packet
.
ReadByte
();
...
...
@@ -277,20 +278,20 @@ namespace WindBot.Game
card
.
SetId
(
packet
.
ReadInt32
());
}
private
void
OnNewTurn
(
GamePacket
Reader
packet
)
private
void
OnNewTurn
(
Binary
Reader
packet
)
{
_duel
.
Turn
++;
_duel
.
Player
=
GetLocalPlayer
(
packet
.
ReadByte
());
_ai
.
OnNewTurn
();
}
private
void
OnNewPhase
(
GamePacket
Reader
packet
)
private
void
OnNewPhase
(
Binary
Reader
packet
)
{
_duel
.
Phase
=
(
DuelPhase
)
packet
.
ReadInt16
();
_ai
.
OnNewPhase
();
}
private
void
OnDamage
(
GamePacket
Reader
packet
)
private
void
OnDamage
(
Binary
Reader
packet
)
{
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
int
final
=
_duel
.
LifePoints
[
player
]
-
packet
.
ReadInt32
();
...
...
@@ -298,19 +299,19 @@ namespace WindBot.Game
_duel
.
LifePoints
[
player
]
=
final
;
}
private
void
OnRecover
(
GamePacket
Reader
packet
)
private
void
OnRecover
(
Binary
Reader
packet
)
{
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
_duel
.
LifePoints
[
player
]
+=
packet
.
ReadInt32
();
}
private
void
OnLpUpdate
(
GamePacket
Reader
packet
)
private
void
OnLpUpdate
(
Binary
Reader
packet
)
{
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
_duel
.
LifePoints
[
player
]
=
packet
.
ReadInt32
();
}
private
void
OnMove
(
GamePacket
Reader
packet
)
private
void
OnMove
(
Binary
Reader
packet
)
{
int
cardId
=
packet
.
ReadInt32
();
int
pc
=
GetLocalPlayer
(
packet
.
ReadByte
());
...
...
@@ -354,7 +355,7 @@ namespace WindBot.Game
}
}
private
void
OnPosChange
(
GamePacket
Reader
packet
)
private
void
OnPosChange
(
Binary
Reader
packet
)
{
packet
.
ReadInt32
();
// card id
int
pc
=
GetLocalPlayer
(
packet
.
ReadByte
());
...
...
@@ -367,7 +368,7 @@ namespace WindBot.Game
card
.
Position
=
cp
;
}
private
void
OnChaining
(
GamePacket
Reader
packet
)
private
void
OnChaining
(
Binary
Reader
packet
)
{
packet
.
ReadInt32
();
// card id
int
pcc
=
GetLocalPlayer
(
packet
.
ReadByte
());
...
...
@@ -379,18 +380,18 @@ namespace WindBot.Game
_ai
.
OnChaining
(
card
,
cc
);
}
private
void
OnChainEnd
(
GamePacket
Reader
packet
)
private
void
OnChainEnd
(
Binary
Reader
packet
)
{
_ai
.
OnChainEnd
();
}
private
void
OnChainSorting
(
GamePacket
Reader
packet
)
private
void
OnChainSorting
(
Binary
Reader
packet
)
{
GamePacketWriter
writer
=
new
GamePacketWriter
(
CtosMessage
.
Response
);
BinaryWriter
writer
=
GamePacketFactory
.
Create
(
CtosMessage
.
Response
);
Connection
.
Send
(
CtosMessage
.
Response
,
-
1
);
}
private
void
OnUpdateCard
(
GamePacket
Reader
packet
)
private
void
OnUpdateCard
(
Binary
Reader
packet
)
{
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
int
loc
=
packet
.
ReadByte
();
...
...
@@ -401,10 +402,10 @@ namespace WindBot.Game
ClientCard
card
=
_duel
.
GetCard
(
player
,
(
CardLocation
)
loc
,
seq
);
if
(
card
==
null
)
return
;
card
.
Update
(
packet
,
_duel
);
card
.
Update
(
packet
,
_duel
);
}
private
void
OnUpdateData
(
GamePacket
Reader
packet
)
private
void
OnUpdateData
(
Binary
Reader
packet
)
{
int
player
=
GetLocalPlayer
(
packet
.
ReadByte
());
CardLocation
loc
=
(
CardLocation
)
packet
.
ReadByte
();
...
...
@@ -440,14 +441,14 @@ namespace WindBot.Game
{
int
len
=
packet
.
ReadInt32
();
if
(
len
==
4
)
continue
;
long
pos
=
packet
.
Position
;
long
pos
=
packet
.
BaseStream
.
Position
;
card
.
Update
(
packet
,
_duel
);
packet
.
Position
=
pos
+
len
-
4
;
packet
.
BaseStream
.
Position
=
pos
+
len
-
4
;
}
}
}
private
void
OnSelectBattleCmd
(
GamePacket
Reader
packet
)
private
void
OnSelectBattleCmd
(
Binary
Reader
packet
)
{
packet
.
ReadByte
();
// player
_duel
.
BattlePhase
=
new
BattlePhase
();
...
...
@@ -494,7 +495,7 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
Response
,
_ai
.
OnSelectBattleCmd
(
battle
).
ToValue
());
}
private
void
InternalOnSelectCard
(
GamePacket
Reader
packet
,
Func
<
IList
<
ClientCard
>,
int
,
int
,
bool
,
IList
<
ClientCard
>>
func
)
private
void
InternalOnSelectCard
(
Binary
Reader
packet
,
Func
<
IList
<
ClientCard
>,
int
,
int
,
bool
,
IList
<
ClientCard
>>
func
)
{
packet
.
ReadByte
();
// player
bool
cancelable
=
packet
.
ReadByte
()
!=
0
;
...
...
@@ -546,17 +547,17 @@ namespace WindBot.Game
result
[
i
+
1
]
=
(
byte
)
id
;
}
GamePacketWriter
reply
=
new
GamePacketWriter
(
CtosMessage
.
Response
);
BinaryWriter
reply
=
GamePacketFactory
.
Create
(
CtosMessage
.
Response
);
reply
.
Write
(
result
);
Connection
.
Send
(
reply
);
}
private
void
OnSelectCard
(
GamePacket
Reader
packet
)
private
void
OnSelectCard
(
Binary
Reader
packet
)
{
InternalOnSelectCard
(
packet
,
_ai
.
OnSelectCard
);
}
private
void
OnSelectChain
(
GamePacket
Reader
packet
)
private
void
OnSelectChain
(
Binary
Reader
packet
)
{
packet
.
ReadByte
();
// player
int
count
=
packet
.
ReadByte
();
...
...
@@ -596,7 +597,7 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
Response
,
_ai
.
OnSelectChain
(
cards
,
descs
,
forced
));
}
private
void
OnSelectCounter
(
GamePacket
Reader
packet
)
private
void
OnSelectCounter
(
Binary
Reader
packet
)
{
packet
.
ReadByte
();
// player
int
type
=
packet
.
ReadInt16
();
...
...
@@ -620,17 +621,17 @@ namespace WindBot.Game
byte
[]
result
=
new
byte
[
used
.
Count
];
for
(
int
i
=
0
;
i
<
quantity
;
++
i
)
result
[
i
]
=
(
byte
)
used
[
i
];
GamePacketWriter
reply
=
new
GamePacketWriter
(
CtosMessage
.
Response
);
BinaryWriter
reply
=
GamePacketFactory
.
Create
(
CtosMessage
.
Response
);
reply
.
Write
(
result
);
Connection
.
Send
(
reply
);
}
private
void
OnSelectDisfield
(
GamePacket
Reader
packet
)
private
void
OnSelectDisfield
(
Binary
Reader
packet
)
{
OnSelectPlace
(
packet
);
}
private
void
OnSelectEffectYn
(
GamePacket
Reader
packet
)
private
void
OnSelectEffectYn
(
Binary
Reader
packet
)
{
packet
.
ReadByte
();
// player
...
...
@@ -653,7 +654,7 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
Response
,
reply
);
}
private
void
OnSelectIdleCmd
(
GamePacket
Reader
packet
)
private
void
OnSelectIdleCmd
(
Binary
Reader
packet
)
{
packet
.
ReadByte
();
// player
...
...
@@ -718,7 +719,7 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
Response
,
_ai
.
OnSelectIdleCmd
(
main
).
ToValue
());
}
private
void
OnSelectOption
(
GamePacket
Reader
packet
)
private
void
OnSelectOption
(
Binary
Reader
packet
)
{
IList
<
int
>
options
=
new
List
<
int
>();
packet
.
ReadByte
();
// player
...
...
@@ -728,7 +729,7 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
Response
,
_ai
.
OnSelectOption
(
options
));
}
private
void
OnSelectPlace
(
GamePacket
Reader
packet
)
private
void
OnSelectPlace
(
Binary
Reader
packet
)
{
packet
.
ReadByte
();
// player
packet
.
ReadByte
();
// min
...
...
@@ -792,12 +793,12 @@ namespace WindBot.Game
if
((
filter
&
0x2
)
!=
0
)
resp
[
2
]
=
7
;
}
GamePacketWriter
reply
=
new
GamePacketWriter
(
CtosMessage
.
Response
);
BinaryWriter
reply
=
GamePacketFactory
.
Create
(
CtosMessage
.
Response
);
reply
.
Write
(
resp
);
Connection
.
Send
(
reply
);
}
private
void
OnSelectPosition
(
GamePacket
Reader
packet
)
private
void
OnSelectPosition
(
Binary
Reader
packet
)
{
packet
.
ReadByte
();
// player
int
cardId
=
packet
.
ReadInt32
();
...
...
@@ -819,7 +820,7 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
Response
,
(
int
)
_ai
.
OnSelectPosition
(
cardId
,
positions
));
}
private
void
OnSelectSum
(
GamePacket
Reader
packet
)
private
void
OnSelectSum
(
Binary
Reader
packet
)
{
packet
.
ReadByte
();
// mode
packet
.
ReadByte
();
// player
...
...
@@ -878,24 +879,24 @@ namespace WindBot.Game
result
[
index
++]
=
(
byte
)
id
;
}
GamePacketWriter
reply
=
new
GamePacketWriter
(
CtosMessage
.
Response
);
BinaryWriter
reply
=
GamePacketFactory
.
Create
(
CtosMessage
.
Response
);
reply
.
Write
(
result
);
Connection
.
Send
(
reply
);
}
private
void
OnSelectTribute
(
GamePacket
Reader
packet
)
private
void
OnSelectTribute
(
Binary
Reader
packet
)
{
InternalOnSelectCard
(
packet
,
_ai
.
OnSelectTribute
);
}
private
void
OnSelectYesNo
(
GamePacket
Reader
packet
)
private
void
OnSelectYesNo
(
Binary
Reader
packet
)
{
packet
.
ReadByte
();
// player
int
reply
=
_ai
.
OnSelectYesNo
(
packet
.
ReadInt32
())
?
(
1
)
:
(
0
);
Connection
.
Send
(
CtosMessage
.
Response
,
reply
);
}
private
void
OnAnnounceAttrib
(
GamePacket
Reader
packet
)
private
void
OnAnnounceAttrib
(
Binary
Reader
packet
)
{
IList
<
CardAttribute
>
attributes
=
new
List
<
CardAttribute
>();
packet
.
ReadByte
();
// player
...
...
@@ -915,12 +916,12 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
Response
,
reply
);
}
private
void
OnAnnounceCard
(
GamePacket
Reader
packet
)
private
void
OnAnnounceCard
(
Binary
Reader
packet
)
{
Connection
.
Send
(
CtosMessage
.
Response
,
_ai
.
OnAnnounceCard
());
}
private
void
OnAnnounceNumber
(
GamePacket
Reader
packet
)
private
void
OnAnnounceNumber
(
Binary
Reader
packet
)
{
IList
<
int
>
numbers
=
new
List
<
int
>();
packet
.
ReadByte
();
// player
...
...
@@ -930,7 +931,7 @@ namespace WindBot.Game
Connection
.
Send
(
CtosMessage
.
Response
,
_ai
.
OnAnnounceNumber
(
numbers
));
}
private
void
OnAnnounceRace
(
GamePacket
Reader
packet
)
private
void
OnAnnounceRace
(
Binary
Reader
packet
)
{
IList
<
CardRace
>
races
=
new
List
<
CardRace
>();
packet
.
ReadByte
();
// player
...
...
Game/GameClient.cs
View file @
c1a1e4fb
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
Core
Client
Connection
{
get
;
private
set
;
}
public
YGO
Client
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
.
Write
Unicode
(
_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
On
MessageReceived
(
object
sender
,
MessageEventArgs
e
)
private
void
On
PacketReceived
(
BinaryReader
reader
)
{
_behavior
.
OnPacket
(
e
.
Message
);
_behavior
.
OnPacket
(
reader
);
}
}
}
\ No newline at end of file
Game/GamePacketFactory.cs
0 → 100644
View file @
c1a1e4fb
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
;
}
}
}
Program.cs
View file @
c1a1e4fb
...
...
@@ -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
;
...
...
WindBot.csproj
View file @
c1a1e4fb
...
...
@@ -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"
/>
...
...
YGOSharp.Network.dll
View file @
c1a1e4fb
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment