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
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
MyCard
windbot
Commits
3b1accc3
Commit
3b1accc3
authored
Jul 26, 2016
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test windbot server
parent
9c6d6fd5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
114 additions
and
33 deletions
+114
-33
Game/AI/Dialogs.cs
Game/AI/Dialogs.cs
+1
-6
Game/GameBehavior.cs
Game/GameBehavior.cs
+6
-0
Game/GameClient.cs
Game/GameClient.cs
+4
-1
Logger.cs
Logger.cs
+4
-0
Program.cs
Program.cs
+98
-26
WindBot.csproj
WindBot.csproj
+1
-0
No files found.
Game/AI/Dialogs.cs
View file @
3b1accc3
...
...
@@ -55,12 +55,7 @@ namespace WindBot.Game.AI
{
_game
=
game
;
DataContractJsonSerializer
serializer
=
new
DataContractJsonSerializer
(
typeof
(
DialogsData
));
string
dialogfilename
=
"zh-CN"
;
string
envdialogfilename
=
Environment
.
GetEnvironmentVariable
(
"YGOPRO_DIALOG"
);
if
(
envdialogfilename
!=
null
)
{
dialogfilename
=
envdialogfilename
;
}
string
dialogfilename
=
game
.
Dialog
;
using
(
FileStream
fs
=
File
.
OpenRead
(
"Dialogs/"
+
dialogfilename
+
".json"
))
{
DialogsData
data
=
(
DialogsData
)
serializer
.
ReadObject
(
fs
);
...
...
Game/GameBehavior.cs
View file @
3b1accc3
...
...
@@ -74,6 +74,7 @@ namespace WindBot.Game
_packets
.
Add
(
StocMessage
.
DuelEnd
,
OnDuelEnd
);
_packets
.
Add
(
StocMessage
.
Chat
,
OnChat
);
_messages
.
Add
(
GameMessage
.
Retry
,
OnRetry
);
_messages
.
Add
(
GameMessage
.
Start
,
OnStart
);
_messages
.
Add
(
GameMessage
.
Win
,
OnWin
);
_messages
.
Add
(
GameMessage
.
Draw
,
OnDraw
);
...
...
@@ -227,6 +228,11 @@ namespace WindBot.Game
packet
.
ReadUnicode
(
256
);
// message
}
private
void
OnRetry
(
BinaryReader
packet
)
{
throw
new
Exception
(
"Got MSG_RETRY."
);
}
private
void
OnStart
(
BinaryReader
packet
)
{
int
type
=
packet
.
ReadByte
();
...
...
Game/GameClient.cs
View file @
3b1accc3
...
...
@@ -12,17 +12,20 @@ namespace WindBot.Game
public
YGOClient
Connection
{
get
;
private
set
;
}
public
string
Username
;
public
string
Deck
;
public
string
Dialog
;
private
string
_serverHost
;
private
int
_serverPort
;
private
string
_roomInfos
;
private
GameBehavior
_behavior
;
public
GameClient
(
string
username
,
string
deck
,
string
serverHost
,
int
serverPort
,
string
roomInfos
=
""
)
public
GameClient
(
string
username
=
"Windbot"
,
string
deck
=
"Blue-Eyes"
,
string
serverHost
=
"127.0.0.1"
,
int
serverPort
=
7911
,
string
dialog
=
"default"
,
string
roomInfos
=
""
)
{
Username
=
username
;
Deck
=
deck
;
Dialog
=
dialog
;
_serverHost
=
serverHost
;
_serverPort
=
serverPort
;
_roomInfos
=
roomInfos
;
...
...
Logger.cs
View file @
3b1accc3
...
...
@@ -8,5 +8,9 @@ namespace WindBot
{
Console
.
WriteLine
(
"["
+
DateTime
.
Now
.
ToString
(
"HH:mm:ss"
)
+
"] "
+
message
);
}
public
static
void
WriteErrorLine
(
string
message
)
{
Console
.
Error
.
WriteLine
(
"["
+
DateTime
.
Now
.
ToString
(
"HH:mm:ss"
)
+
"] "
+
message
);
}
}
}
\ No newline at end of file
Program.cs
View file @
3b1accc3
...
...
@@ -4,29 +4,82 @@ using System.IO;
using
System.Threading
;
using
WindBot.Game
;
using
WindBot.Game.AI
;
using
System.Net
;
using
System.Web
;
namespace
WindBot
{
public
class
WindBotInfo
{
public
string
Name
{
get
;
set
;
}
public
string
Deck
{
get
;
set
;
}
public
string
Host
{
get
;
set
;
}
public
string
Dialog
{
get
;
set
;
}
public
int
Port
{
get
;
set
;
}
public
int
Version
{
get
;
set
;
}
}
public
class
Program
{
public
static
short
ProVersion
=
0x133A
;
public
static
int
PlayerNameSize
=
20
;
internal
static
Random
Rand
;
internal
static
void
Main
()
{
#if !DEBUG
try
{
Run
();
}
catch
(
Exception
ex
)
Init
(
"cards.cdb"
);
using
(
HttpListener
MainServer
=
new
HttpListener
())
{
Console
.
Error
.
WriteLine
(
"Error: "
+
ex
);
MainServer
.
AuthenticationSchemes
=
AuthenticationSchemes
.
Anonymous
;
MainServer
.
Prefixes
.
Add
(
"http://127.0.0.1:2399/"
);
MainServer
.
Start
();
Console
.
WriteLine
(
"Windbot Server Start Successed."
);
while
(
true
)
{
try
{
HttpListenerContext
ctx
=
MainServer
.
GetContext
();
WindBotInfo
Info
=
new
WindBotInfo
();
string
RawUrl
=
Path
.
GetFileName
(
ctx
.
Request
.
RawUrl
);
Info
.
Name
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"name"
);
Info
.
Deck
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"deck"
);
Info
.
Host
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"host"
);
Info
.
Dialog
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"dialog"
);
string
port
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"port"
);
if
(
port
!=
null
)
Info
.
Port
=
Int32
.
Parse
(
port
);
string
version
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"version"
);
if
(
version
!=
null
)
Info
.
Version
=
Int16
.
Parse
(
version
);
if
(
Info
.
Name
==
null
||
Info
.
Deck
==
null
||
Info
.
Host
==
null
||
Info
.
Dialog
==
null
||
port
==
null
||
version
==
null
)
{
ctx
.
Response
.
StatusCode
=
400
;
ctx
.
Response
.
Close
();
}
else
{
try
{
Thread
workThread
=
new
Thread
(
new
ParameterizedThreadStart
(
Run
));
workThread
.
Start
(
Info
);
}
catch
(
Exception
ex
)
{
Logger
.
WriteErrorLine
(
"Start Thread Error: "
+
ex
);
}
ctx
.
Response
.
StatusCode
=
200
;
ctx
.
Response
.
Close
();
}
}
catch
(
Exception
ex
)
{
Logger
.
WriteErrorLine
(
"Parse Http Request Error: "
+
ex
);
}
}
}
#else
Run
();
#endif
}
public
static
void
Init
(
string
databasePath
)
...
...
@@ -36,33 +89,52 @@ namespace WindBot
InitCardsManager
(
databasePath
);
}
private
static
void
Run
(
)
private
static
void
InitCardsManager
(
string
databasePath
)
{
Init
(
"cards.cdb"
);
GameClient
client
;
string
EnvName
=
Environment
.
GetEnvironmentVariable
(
"YGOPRO_NAME"
);
if
(
EnvName
!=
null
)
string
currentPath
=
Path
.
GetFullPath
(
"."
);
string
absolutePath
=
Path
.
Combine
(
currentPath
,
databasePath
);
NamedCardsManager
.
Init
(
absolutePath
);
}
private
static
void
Run
(
object
o
)
{
#if !DEBUG
try
{
ProVersion
=
Int16
.
Parse
(
Environment
.
GetEnvironmentVariable
(
"YGOPRO_VERSION"
));
client
=
new
GameClient
(
EnvName
,
Environment
.
GetEnvironmentVariable
(
"YGOPRO_DECK"
),
Environment
.
GetEnvironmentVariable
(
"YGOPRO_HOST"
),
Int32
.
Parse
(
Environment
.
GetEnvironmentVariable
(
"YGOPRO_PORT"
)));
WindBotInfo
Info
=
(
WindBotInfo
)
o
;
GameClient
client
=
new
GameClient
(
Info
.
Name
,
Info
.
Deck
,
Info
.
Host
,
Info
.
Port
,
Info
.
Dialog
);
client
.
Start
();
Logger
.
WriteLine
(
client
.
Username
+
" started."
);
while
(
client
.
Connection
.
IsConnected
)
{
try
{
client
.
Tick
();
Thread
.
Sleep
(
30
);
}
catch
(
Exception
ex
)
{
Logger
.
WriteErrorLine
(
"Tick Error: "
+
ex
);
}
}
Logger
.
WriteLine
(
client
.
Username
+
" end."
);
}
else
catch
(
Exception
ex
)
{
client
=
new
GameClient
(
"谜之剑士LV4"
,
"Blue-Eyes"
,
"127.0.0.1"
,
7911
);
Logger
.
WriteErrorLine
(
"Run Error: "
+
ex
);
}
#else
WindBotInfo
Info
=
(
WindBotInfo
)
o
;
GameClient
client
=
new
GameClient
(
Info
.
Name
,
Info
.
Deck
,
Info
.
Host
,
Info
.
Port
,
Info
.
Dialog
);
client
.
Start
();
Logger
.
WriteLine
(
client
.
Username
+
" started."
);
while
(
client
.
Connection
.
IsConnected
)
{
client
.
Tick
();
Thread
.
Sleep
(
30
);
}
}
private
static
void
InitCardsManager
(
string
databasePath
)
{
string
currentPath
=
Path
.
GetFullPath
(
"."
);
string
absolutePath
=
Path
.
Combine
(
currentPath
,
databasePath
);
NamedCardsManager
.
Init
(
absolutePath
);
Logger
.
WriteLine
(
client
.
Username
+
" end."
);
#endif
}
}
}
WindBot.csproj
View file @
3b1accc3
...
...
@@ -42,6 +42,7 @@
<Reference
Include=
"System.Core"
/>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.Runtime.Serialization"
/>
<Reference
Include=
"System.Web"
/>
<Reference
Include=
"System.Xml"
/>
<Reference
Include=
"YGOSharp.Network"
>
<HintPath>
.\YGOSharp.Network.dll
</HintPath>
...
...
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