Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
W
Windbot-408
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
神之吹息
Windbot-408
Commits
fc10fcec
Commit
fc10fcec
authored
Nov 03, 2017
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove safe mode eventually
"catch when" was included in C#6.0, which shouldn't be neccessary
parent
c626f14f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
73 deletions
+83
-73
Program.cs
Program.cs
+83
-73
No files found.
Program.cs
View file @
fc10fcec
...
@@ -11,13 +11,6 @@ namespace WindBot
...
@@ -11,13 +11,6 @@ namespace WindBot
{
{
public
class
Program
public
class
Program
{
{
// In safe mode, all errors will be catched instead of causing the program to crash.
#if DEBUG
public
static
bool
SafeMode
=
false
;
#else
public
static
bool
SafeMode
=
true
;
#endif
internal
static
Random
Rand
;
internal
static
Random
Rand
;
internal
static
void
Main
(
string
[]
args
)
internal
static
void
Main
(
string
[]
args
)
...
@@ -89,85 +82,102 @@ namespace WindBot
...
@@ -89,85 +82,102 @@ namespace WindBot
Logger
.
WriteLine
(
"HTTP GET http://127.0.0.1:"
+
ServerPort
+
"/?name=WindBot&host=127.0.0.1&port=7911 to call the bot."
);
Logger
.
WriteLine
(
"HTTP GET http://127.0.0.1:"
+
ServerPort
+
"/?name=WindBot&host=127.0.0.1&port=7911 to call the bot."
);
while
(
true
)
while
(
true
)
{
{
try
#if !DEBUG
{
try
HttpListenerContext
ctx
=
MainServer
.
GetContext
();
{
#endif
HttpListenerContext
ctx
=
MainServer
.
GetContext
();
WindBotInfo
Info
=
new
WindBotInfo
();
WindBotInfo
Info
=
new
WindBotInfo
();
string
RawUrl
=
Path
.
GetFileName
(
ctx
.
Request
.
RawUrl
);
string
RawUrl
=
Path
.
GetFileName
(
ctx
.
Request
.
RawUrl
);
Info
.
Name
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"name"
);
Info
.
Name
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"name"
);
Info
.
Deck
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"deck"
);
Info
.
Deck
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"deck"
);
Info
.
Host
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"host"
);
Info
.
Host
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"host"
);
string
port
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"port"
);
string
port
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"port"
);
if
(
port
!=
null
)
if
(
port
!=
null
)
Info
.
Port
=
Int32
.
Parse
(
port
);
Info
.
Port
=
Int32
.
Parse
(
port
);
string
dialog
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"dialog"
);
string
dialog
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"dialog"
);
if
(
dialog
!=
null
)
if
(
dialog
!=
null
)
Info
.
Dialog
=
dialog
;
Info
.
Dialog
=
dialog
;
string
version
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"version"
);
string
version
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"version"
);
if
(
version
!=
null
)
if
(
version
!=
null
)
Info
.
Version
=
Int16
.
Parse
(
version
);
Info
.
Version
=
Int16
.
Parse
(
version
);
string
password
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"password"
);
string
password
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"password"
);
if
(
password
!=
null
)
if
(
password
!=
null
)
Info
.
HostInfo
=
password
;
Info
.
HostInfo
=
password
;
string
hand
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"hand"
);
string
hand
=
HttpUtility
.
ParseQueryString
(
RawUrl
).
Get
(
"hand"
);
if
(
hand
!=
null
)
if
(
hand
!=
null
)
Info
.
Hand
=
Int32
.
Parse
(
hand
);
Info
.
Hand
=
Int32
.
Parse
(
hand
);
if
(
Info
.
Name
==
null
||
Info
.
Host
==
null
||
port
==
null
)
if
(
Info
.
Name
==
null
||
Info
.
Host
==
null
||
port
==
null
)
{
{
ctx
.
Response
.
StatusCode
=
400
;
ctx
.
Response
.
StatusCode
=
400
;
ctx
.
Response
.
Close
();
ctx
.
Response
.
Close
();
}
else
{
try
{
Thread
workThread
=
new
Thread
(
new
ParameterizedThreadStart
(
Run
));
workThread
.
Start
(
Info
);
}
catch
(
Exception
ex
)
when
(
SafeMode
)
{
Logger
.
WriteErrorLine
(
"Start Thread Error: "
+
ex
);
}
ctx
.
Response
.
StatusCode
=
200
;
ctx
.
Response
.
Close
();
}
}
}
catch
(
Exception
ex
)
when
(
SafeMode
)
else
{
{
Logger
.
WriteErrorLine
(
"Parse Http Request Error: "
+
ex
);
#if !DEBUG
try
{
#endif
Thread
workThread
=
new
Thread
(
new
ParameterizedThreadStart
(
Run
));
workThread
.
Start
(
Info
);
#if !DEBUG
}
catch
(
Exception
ex
)
{
Logger
.
WriteErrorLine
(
"Start Thread Error: "
+
ex
);
}
#endif
ctx
.
Response
.
StatusCode
=
200
;
ctx
.
Response
.
Close
();
}
}
#if !DEBUG
}
catch
(
Exception
ex
)
{
Logger
.
WriteErrorLine
(
"Parse Http Request Error: "
+
ex
);
}
#endif
}
}
}
}
}
}
private
static
void
Run
(
object
o
)
private
static
void
Run
(
object
o
)
{
{
try
#if !DEBUG
{
try
WindBotInfo
Info
=
(
WindBotInfo
)
o
;
{
GameClient
client
=
new
GameClient
(
Info
);
//all errors will be catched instead of causing the program to crash.
client
.
Start
();
#endif
Logger
.
DebugWriteLine
(
client
.
Username
+
" started."
);
WindBotInfo
Info
=
(
WindBotInfo
)
o
;
while
(
client
.
Connection
.
IsConnected
)
GameClient
client
=
new
GameClient
(
Info
);
{
client
.
Start
();
try
Logger
.
DebugWriteLine
(
client
.
Username
+
" started."
);
{
while
(
client
.
Connection
.
IsConnected
)
client
.
Tick
();
Thread
.
Sleep
(
30
);
}
catch
(
Exception
ex
)
when
(
SafeMode
)
{
Logger
.
WriteErrorLine
(
"Tick Error: "
+
ex
);
}
}
Logger
.
DebugWriteLine
(
client
.
Username
+
" end."
);
}
catch
(
Exception
ex
)
when
(
SafeMode
)
{
{
Logger
.
WriteErrorLine
(
"Run Error: "
+
ex
);
#if !DEBUG
try
{
#endif
client
.
Tick
();
Thread
.
Sleep
(
30
);
#if !DEBUG
}
catch
(
Exception
ex
)
{
Logger
.
WriteErrorLine
(
"Tick Error: "
+
ex
);
}
#endif
}
}
Logger
.
DebugWriteLine
(
client
.
Username
+
" end."
);
#if !DEBUG
}
catch
(
Exception
ex
)
{
Logger
.
WriteErrorLine
(
"Run Error: "
+
ex
);
}
#endif
}
}
}
}
}
}
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