Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
guo450212436
et
提交
707e1d16
E
et
项目概览
guo450212436
/
et
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
et
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
707e1d16
编写于
10月 20, 2016
作者:
T
tanghai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加管理App类型,所有进程由管理App管理,启动,停止,Reload等等
上级
03fe34ac
变更
23
隐藏空白更改
内联
并排
Showing
23 changed file
with
259 addition
and
147 deletion
+259
-147
Server/App/Program.cs
Server/App/Program.cs
+6
-10
Server/Base/Server.Base.csproj
Server/Base/Server.Base.csproj
+3
-0
Server/Model/Component/AppManagerComponent.cs
Server/Model/Component/AppManagerComponent.cs
+50
-0
Server/Model/Component/OptionsComponent.cs
Server/Model/Component/OptionsComponent.cs
+6
-0
Server/Model/Component/RealmGateAddressComponent.cs
Server/Model/Component/RealmGateAddressComponent.cs
+5
-8
Server/Model/Helper/DllHelper.cs
Server/Model/Helper/DllHelper.cs
+20
-0
Server/Model/Server.Model.csproj
Server/Model/Server.Model.csproj
+3
-3
Server/Server.sln
Server/Server.sln
+0
-15
Unity/Assets/Editor/ServerCommandLineEditor/UI/ServerCommandLineEditor.cs
...tor/ServerCommandLineEditor/UI/ServerCommandLineEditor.cs
+28
-29
Unity/Assets/Plugins/Base/Helper/NetHelper.cs
Unity/Assets/Plugins/Base/Helper/NetHelper.cs
+22
-0
Unity/Assets/Plugins/Base/Helper/NetHelper.cs.meta
Unity/Assets/Plugins/Base/Helper/NetHelper.cs.meta
+2
-2
Unity/Assets/Scripts/Component/AppInfoComponent.cs
Unity/Assets/Scripts/Component/AppInfoComponent.cs
+0
-23
Unity/Assets/Scripts/Component/TimerComponent.cs
Unity/Assets/Scripts/Component/TimerComponent.cs
+26
-30
Unity/Assets/Scripts/Helper.meta
Unity/Assets/Scripts/Helper.meta
+9
-0
Unity/Assets/Scripts/Helper/DllHelper.cs
Unity/Assets/Scripts/Helper/DllHelper.cs
+17
-0
Unity/Assets/Scripts/Helper/DllHelper.cs.meta
Unity/Assets/Scripts/Helper/DllHelper.cs.meta
+12
-0
Unity/Assets/Scripts/Init.cs
Unity/Assets/Scripts/Init.cs
+1
-6
Unity/Assets/Scripts/Message/AppType.cs
Unity/Assets/Scripts/Message/AppType.cs
+1
-0
Unity/Assets/Scripts/Other/CommandLine.cs
Unity/Assets/Scripts/Other/CommandLine.cs
+27
-13
Unity/Assets/Scripts/Other/Options.cs
Unity/Assets/Scripts/Other/Options.cs
+17
-6
Unity/Controller/Event/InitSceneStartEvent_InitGame.cs
Unity/Controller/Event/InitSceneStartEvent_InitGame.cs
+1
-1
Unity/Unity.CSharp.Plugins.csproj
Unity/Unity.CSharp.Plugins.csproj
+1
-0
Unity/Unity.CSharp.csproj
Unity/Unity.CSharp.csproj
+2
-1
未找到文件。
Server/App/Program.cs
浏览文件 @
707e1d16
...
...
@@ -17,14 +17,7 @@ namespace App
Object
.
ObjectManager
.
Register
(
"Base"
,
typeof
(
Game
).
Assembly
);
Object
.
ObjectManager
.
Register
(
"Model"
,
typeof
(
ErrorCode
).
Assembly
);
byte
[]
dllBytes
=
File
.
ReadAllBytes
(
"./Controller.dll"
);
#if __MonoCS__
byte
[]
pdbBytes
=
File
.
ReadAllBytes
(
"./Controller.dll.mdb"
);
#else
byte
[]
pdbBytes
=
File
.
ReadAllBytes
(
"./Controller.pdb"
);
#endif
Assembly
controller
=
Assembly
.
Load
(
dllBytes
,
pdbBytes
);
Object
.
ObjectManager
.
Register
(
"Controller"
,
controller
);
Object
.
ObjectManager
.
Register
(
"Controller"
,
DllHelper
.
GetController
());
Options
options
=
Game
.
Scene
.
AddComponent
<
OptionsComponent
,
string
[
]>
(
args
).
Options
;
...
...
@@ -36,10 +29,13 @@ namespace App
// 根据不同的AppType添加不同的组件
switch
(
options
.
AppType
)
{
case
"Realm"
:
case
AppType
.
Manager
:
Game
.
Scene
.
AddComponent
<
AppManagerComponent
>();
break
;
case
AppType
.
Realm
:
Game
.
Scene
.
AddComponent
<
RealmGateAddressComponent
>();
break
;
case
"Gate"
:
case
AppType
.
Gate
:
Game
.
Scene
.
AddComponent
<
GateSessionKeyComponent
>();
break
;
default
:
...
...
Server/Base/Server.Base.csproj
浏览文件 @
707e1d16
...
...
@@ -104,6 +104,9 @@
<Compile
Include=
"..\..\Unity\Assets\Plugins\Base\Helper\MongoHelper.cs"
>
<Link>
Helper\MongoHelper.cs
</Link>
</Compile>
<Compile
Include=
"..\..\Unity\Assets\Plugins\Base\Helper\NetHelper.cs"
>
<Link>
Helper\NetHelper.cs
</Link>
</Compile>
<Compile
Include=
"..\..\Unity\Assets\Plugins\Base\Helper\ProtobufHelper.cs"
>
<Link>
Helper\ProtobufHelper.cs
</Link>
</Compile>
...
...
Server/Model/Component/AppManagerComponent.cs
0 → 100644
浏览文件 @
707e1d16
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.IO
;
using
System.Linq
;
using
Base
;
namespace
Model
{
[
ObjectEvent
]
public
class
AppManagerComponentEvent
:
ObjectEvent
<
AppManagerComponent
>,
IAwake
{
public
void
Awake
()
{
this
.
GetValue
().
Awake
();
}
}
public
class
AppManagerComponent
:
Component
{
private
readonly
Dictionary
<
int
,
Process
>
processes
=
new
Dictionary
<
int
,
Process
>();
public
void
Awake
()
{
string
[]
ips
=
NetHelper
.
GetAddressIPs
();
CommandLines
commandLines
=
Game
.
Scene
.
GetComponent
<
OptionsComponent
>().
AllOptions
;
foreach
(
Options
options
in
commandLines
.
Options
)
{
if
(!
ips
.
Contains
(
options
.
IP
))
{
continue
;
}
if
(
options
.
AppType
==
AppType
.
Manager
)
{
continue
;
}
string
arguments
=
$"--appType=
{
options
.
AppType
}
--id=
{
options
.
Id
}
--Protocol=
{
options
.
Protocol
}
--Host=
{
options
.
Host
}
--Port=
{
options
.
Port
}
"
;
ProcessStartInfo
info
=
new
ProcessStartInfo
(
@"App.exe"
,
arguments
)
{
UseShellExecute
=
true
,
WorkingDirectory
=
@"..\Server\Bin\Debug"
};
Process
process
=
Process
.
Start
(
info
);
this
.
processes
.
Add
(
process
.
Id
,
process
);
}
}
}
}
\ No newline at end of file
Server/Model/Component/OptionsComponent.cs
浏览文件 @
707e1d16
using
System
;
using
System.IO
;
using
Base
;
using
CommandLine
;
...
...
@@ -15,10 +16,15 @@ namespace Model
public
class
OptionsComponent
:
Component
{
public
CommandLines
AllOptions
=
new
CommandLines
();
public
Options
Options
=
new
Options
();
public
void
Awake
(
string
[]
args
)
{
string
s
=
File
.
ReadAllText
(
"./CommandLineConfig.txt"
);
this
.
AllOptions
=
MongoHelper
.
FromJson
<
CommandLines
>(
s
);
if
(!
Parser
.
Default
.
ParseArguments
(
args
,
this
.
Options
))
{
throw
new
Exception
(
$"命令行格式错误!"
);
...
...
Server/Model/Component/RealmGateAddressComponent.cs
浏览文件 @
707e1d16
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Collections.Generic
;
using
Base
;
namespace
Model
...
...
@@ -20,15 +18,14 @@ namespace Model
public
void
Awake
()
{
string
s
=
File
.
ReadAllText
(
"./CommandLineConfig.txt"
);
CommandLines
commandLines
=
MongoHelper
.
FromJson
<
CommandLines
>(
s
);
foreach
(
CommandLine
commandLine
in
commandLines
.
Commands
)
CommandLines
commandLines
=
this
.
GetComponent
<
OptionsComponent
>().
AllOptions
;
foreach
(
Options
options
in
commandLines
.
Options
)
{
if
(
commandLine
.
O
ptions
.
AppType
!=
"Gate"
)
if
(
o
ptions
.
AppType
!=
"Gate"
)
{
continue
;
}
this
.
GateAddress
.
Add
(
$"
{
commandLine
.
Options
.
Host
}
:
{
commandLine
.
O
ptions
.
Port
}
"
);
this
.
GateAddress
.
Add
(
$"
{
options
.
Host
}
:
{
o
ptions
.
Port
}
"
);
}
}
...
...
Server/Model/Helper/DllHelper.cs
0 → 100644
浏览文件 @
707e1d16
using
System.IO
;
using
System.Reflection
;
namespace
Model
{
public
static
class
DllHelper
{
public
static
Assembly
GetController
()
{
byte
[]
dllBytes
=
File
.
ReadAllBytes
(
"./Controller.dll"
);
#if __MonoCS__
byte
[]
pdbBytes
=
File
.
ReadAllBytes
(
"./Controller.dll.mdb"
);
#else
byte
[]
pdbBytes
=
File
.
ReadAllBytes
(
"./Controller.pdb"
);
#endif
Assembly
assembly
=
Assembly
.
Load
(
dllBytes
,
pdbBytes
);
return
assembly
;
}
}
}
Server/Model/Server.Model.csproj
浏览文件 @
707e1d16
...
...
@@ -41,9 +41,6 @@
<Reference
Include=
"System.Core"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"..\..\Unity\Assets\Scripts\Component\AppInfoComponent.cs"
>
<Link>
Component\AppInfoComponent.cs
</Link>
</Compile>
<Compile
Include=
"..\..\Unity\Assets\Scripts\Component\EventComponent.cs"
>
<Link>
Component\EventComponent.cs
</Link>
</Compile>
...
...
@@ -83,10 +80,12 @@
<Compile
Include=
"..\..\Unity\Assets\Scripts\Other\Options.cs"
>
<Link>
Other\Options.cs
</Link>
</Compile>
<Compile
Include=
"Component\AppManagerComponent.cs"
/>
<Compile
Include=
"Component\LogToClientComponent.cs"
/>
<Compile
Include=
"Component\GateSessionKeyComponent.cs"
/>
<Compile
Include=
"Component\RealmGateAddressComponent.cs"
/>
<Compile
Include=
"Component\OptionsComponent.cs"
/>
<Compile
Include=
"Helper\DllHelper.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
<ItemGroup>
...
...
@@ -95,6 +94,7 @@
<Name>
Server.Base
</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup
/>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
...
...
Server/Server.sln
浏览文件 @
707e1d16
...
...
@@ -15,8 +15,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ENet", "ThirdParty\ENet\ENe
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.App", "App\Server.App.csproj", "{3F8DC04C-9E05-403F-B6A5-36293EB99937}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nuget", "ThirdParty\Nuget\Nuget.csproj", "{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
...
...
@@ -85,24 +83,11 @@ Global
{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x64.Build.0 = Release|Any CPU
{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x86.ActiveCfg = Release|Any CPU
{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x86.Build.0 = Release|Any CPU
{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|x64.ActiveCfg = Debug|Any CPU
{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|x64.Build.0 = Debug|Any CPU
{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|x86.ActiveCfg = Debug|Any CPU
{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|x86.Build.0 = Debug|Any CPU
{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|Any CPU.Build.0 = Release|Any CPU
{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|x64.ActiveCfg = Release|Any CPU
{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|x64.Build.0 = Release|Any CPU
{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|x86.ActiveCfg = Release|Any CPU
{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{C9992B7C-313E-4C9F-A954-640D01EDFB58} = {01CCAD69-09B1-42F9-8A39-489268BEE18D}
{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135} = {01CCAD69-09B1-42F9-8A39-489268BEE18D}
EndGlobalSection
EndGlobal
Unity/Assets/Editor/ServerCommandLineEditor/UI/ServerCommandLineEditor.cs
浏览文件 @
707e1d16
...
...
@@ -37,36 +37,36 @@ namespace MyEditor
void
OnGUI
()
{
for
(
int
i
=
0
;
i
<
this
.
commandLines
.
Command
s
.
Count
;
++
i
)
for
(
int
i
=
0
;
i
<
this
.
commandLines
.
Option
s
.
Count
;
++
i
)
{
CommandLine
commandLine
=
this
.
commandLines
.
Command
s
[
i
];
Options
options
=
this
.
commandLines
.
Option
s
[
i
];
GUILayout
.
BeginHorizontal
();
GUILayout
.
Label
(
$"IP:"
);
commandLine
.
IP
=
EditorGUILayout
.
TextField
(
commandLine
.
IP
);
GUILayout
.
Label
(
$"AppType:"
);
commandLine
.
Options
.
AppType
=
EditorGUILayout
.
TextField
(
commandLine
.
Options
.
AppType
);
GUILayout
.
Label
(
$"Id:"
);
commandLine
.
Options
.
Id
=
EditorGUILayout
.
IntField
(
commandLine
.
Options
.
Id
);
options
.
Id
=
EditorGUILayout
.
IntField
(
options
.
Id
);
GUILayout
.
Label
(
$"服务器IP:"
);
options
.
IP
=
EditorGUILayout
.
TextField
(
options
.
IP
);
GUILayout
.
Label
(
$"AppType:"
);
options
.
AppType
=
EditorGUILayout
.
TextField
(
options
.
AppType
);
GUILayout
.
Label
(
$"Protocol:"
);
commandLine
.
Options
.
Protocol
=
(
NetworkProtocol
)
EditorGUILayout
.
EnumPopup
(
commandLine
.
O
ptions
.
Protocol
);
options
.
Protocol
=
(
NetworkProtocol
)
EditorGUILayout
.
EnumPopup
(
o
ptions
.
Protocol
);
GUILayout
.
Label
(
$"Host:"
);
commandLine
.
Options
.
Host
=
EditorGUILayout
.
TextField
(
commandLine
.
O
ptions
.
Host
);
options
.
Host
=
EditorGUILayout
.
TextField
(
o
ptions
.
Host
);
GUILayout
.
Label
(
$"Port:"
);
commandLine
.
Options
.
Port
=
EditorGUILayout
.
IntField
(
commandLine
.
O
ptions
.
Port
);
options
.
Port
=
EditorGUILayout
.
IntField
(
o
ptions
.
Port
);
if
(
GUILayout
.
Button
(
"删除"
))
{
this
.
commandLines
.
Commands
.
Remove
(
commandLine
);
this
.
commandLines
.
Options
.
Remove
(
options
);
break
;
}
if
(
GUILayout
.
Button
(
"复制"
))
{
for
(
int
j
=
1
;
j
<
this
.
copyNum
+
1
;
++
j
)
{
CommandLine
newCommandLine
=
(
CommandLine
)
commandLine
.
Clone
();
new
CommandLine
.
Options
.
Id
+=
j
;
new
CommandLine
.
Options
.
Port
+=
j
;
new
CommandLine
.
Options
.
Protocol
=
this
.
protocol
;
this
.
commandLines
.
Commands
.
Add
(
newCommandLine
);
Options
newOptions
=
(
Options
)
options
.
Clone
();
newOptions
.
Id
+=
j
;
newOptions
.
Port
+=
j
;
newOptions
.
Protocol
=
this
.
protocol
;
this
.
commandLines
.
Options
.
Add
(
newOptions
);
}
break
;
}
...
...
@@ -81,9 +81,9 @@ namespace MyEditor
GUILayout
.
BeginHorizontal
();
if
(
GUILayout
.
Button
(
"添加"
))
{
CommandLine
newCommandLine
=
new
CommandLine
();
new
CommandLine
.
Options
.
Protocol
=
this
.
protocol
;
this
.
commandLines
.
Commands
.
Add
(
newCommandLine
);
Options
newOptions
=
new
Options
();
newOptions
.
Protocol
=
this
.
protocol
;
this
.
commandLines
.
Options
.
Add
(
newOptions
);
}
if
(
GUILayout
.
Button
(
"保存"
))
...
...
@@ -93,17 +93,16 @@ namespace MyEditor
if
(
GUILayout
.
Button
(
"启动"
))
{
foreach
(
CommandLine
commandLine
in
this
.
commandLines
.
Commands
)
{
string
arguments
=
$"--appType=
{
commandLine
.
Options
.
AppType
}
--id=
{
commandLine
.
Options
.
Id
}
--Protocol=
{
commandLine
.
Options
.
Protocol
}
--Host=
{
commandLine
.
Options
.
Host
}
--Port=
{
commandLine
.
O
ptions
.
Port
}
"
;
Options
options
=
this
.
commandLines
.
Manager
;
string
arguments
=
$"--appType=
{
options
.
AppType
}
--id=
{
options
.
Id
}
--Protocol=
{
options
.
Protocol
}
--Host=
{
options
.
Host
}
--Port=
{
o
ptions
.
Port
}
"
;
ProcessStartInfo
info
=
new
ProcessStartInfo
(
@"App.exe"
,
arguments
)
{
UseShellExecute
=
true
,
WorkingDirectory
=
@"..\Server\Bin\Debug"
};
Process
.
Start
(
info
);
}
ProcessStartInfo
info
=
new
ProcessStartInfo
(
@"App.exe"
,
arguments
)
{
UseShellExecute
=
true
,
WorkingDirectory
=
@"..\Server\Bin\Debug"
};
Process
.
Start
(
info
);
}
GUILayout
.
EndHorizontal
();
}
...
...
Unity/Assets/Plugins/Base/Helper/NetHelper.cs
0 → 100644
浏览文件 @
707e1d16
using
System.Collections.Generic
;
using
System.Net
;
namespace
Base
{
public
static
class
NetHelper
{
public
static
string
[]
GetAddressIPs
()
{
//获取本地的IP地址
List
<
string
>
addressIPs
=
new
List
<
string
>();
foreach
(
IPAddress
address
in
Dns
.
GetHostEntry
(
Dns
.
GetHostName
()).
AddressList
)
{
if
(
address
.
AddressFamily
.
ToString
()
==
"InterNetwork"
)
{
addressIPs
.
Add
(
address
.
ToString
());
}
}
return
addressIPs
.
ToArray
();
}
}
}
Unity/Assets/
Scripts/Component/AppInfoComponent
.cs.meta
→
Unity/Assets/
Plugins/Base/Helper/NetHelper
.cs.meta
浏览文件 @
707e1d16
fileFormatVersion: 2
guid:
d4852a0f714d73f43af0109603bd32ba
timeCreated: 1476
849603
guid:
118568110604b5f4ebb8e56ca26d4f13
timeCreated: 1476
940305
licenseType: Pro
MonoImporter:
serializedVersion: 2
...
...
Unity/Assets/Scripts/Component/AppInfoComponent.cs
已删除
100644 → 0
浏览文件 @
03fe34ac
using
Base
;
namespace
Model
{
[
ObjectEvent
]
public
class
AppInfoComponentEvent
:
ObjectEvent
<
AppInfoComponent
>,
IAwake
<
string
>
{
public
void
Awake
(
string
appType
)
{
this
.
GetValue
().
Awake
(
appType
);
}
}
public
class
AppInfoComponent
:
Component
{
private
string
AppType
{
get
;
set
;
}
public
void
Awake
(
string
appType
)
{
this
.
AppType
=
appType
;
}
}
}
\ No newline at end of file
Unity/Assets/Scripts/Component/TimerComponent.cs
浏览文件 @
707e1d16
...
...
@@ -2,19 +2,18 @@
using
System.Threading
;
using
System.Threading.Tasks
;
using
Base
;
using
MongoDB.Bson
;
namespace
Model
{
public
class
Timer
{
public
ObjectId
Id
{
get
;
set
;
}
public
long
Id
{
get
;
set
;
}
public
long
Time
{
get
;
set
;
}
public
TaskCompletionSource
<
bool
>
tcs
;
}
[
ObjectEvent
]
public
class
TimerComponentEvent
:
ObjectEvent
<
TimerComponent
>
public
class
TimerComponentEvent
:
ObjectEvent
<
TimerComponent
>
,
IUpdate
{
public
void
Update
()
{
...
...
@@ -23,50 +22,47 @@ namespace Model
}
}
public
static
class
TimerComponentExtension
public
class
TimerComponent
:
Component
{
public
static
void
Update
(
this
TimerComponent
component
)
private
readonly
Dictionary
<
long
,
Timer
>
timers
=
new
Dictionary
<
long
,
Timer
>();
/// <summary>
/// key: time, value: timer id
/// </summary>
private
readonly
MultiMap
<
long
,
long
>
timeId
=
new
MultiMap
<
long
,
long
>();
private
readonly
Queue
<
long
>
timeoutTimer
=
new
Queue
<
long
>();
public
void
Update
()
{
long
timeNow
=
TimeHelper
.
Now
();
foreach
(
long
time
in
component
.
timeId
.
Keys
)
foreach
(
long
time
in
this
.
timeId
.
Keys
)
{
if
(
time
>
timeNow
)
{
break
;
}
component
.
timeoutTimer
.
Enqueue
(
time
);
this
.
timeoutTimer
.
Enqueue
(
time
);
}
while
(
component
.
timeoutTimer
.
Count
>
0
)
while
(
this
.
timeoutTimer
.
Count
>
0
)
{
long
key
=
component
.
timeoutTimer
.
Dequeue
();
ObjectId
[]
timeOutId
=
component
.
timeId
.
GetAll
(
key
);
foreach
(
ObjectId
id
in
timeOutId
)
long
key
=
this
.
timeoutTimer
.
Dequeue
();
long
[]
timeOutId
=
this
.
timeId
.
GetAll
(
key
);
foreach
(
long
id
in
timeOutId
)
{
Timer
timer
;
if
(!
component
.
timers
.
TryGetValue
(
id
,
out
timer
))
if
(!
this
.
timers
.
TryGetValue
(
id
,
out
timer
))
{
continue
;
}
component
.
Remove
(
id
);
this
.
Remove
(
id
);
timer
.
tcs
.
SetResult
(
true
);
}
}
}
}
public
class
TimerComponent
:
Component
{
public
readonly
Dictionary
<
ObjectId
,
Timer
>
timers
=
new
Dictionary
<
ObjectId
,
Timer
>();
/// <summary>
/// key: time, value: timer id
/// </summary>
public
readonly
MultiMap
<
long
,
ObjectId
>
timeId
=
new
MultiMap
<
long
,
ObjectId
>();
public
readonly
Queue
<
long
>
timeoutTimer
=
new
Queue
<
long
>();
p
ublic
void
Remove
(
ObjectId
id
)
p
rivate
void
Remove
(
long
id
)
{
Timer
timer
;
if
(!
this
.
timers
.
TryGetValue
(
id
,
out
timer
))
...
...
@@ -80,7 +76,7 @@ namespace Model
public
Task
WaitTillAsync
(
long
tillTime
,
CancellationToken
cancellationToken
)
{
TaskCompletionSource
<
bool
>
tcs
=
new
TaskCompletionSource
<
bool
>();
Timer
timer
=
new
Timer
{
Id
=
ObjectId
.
GenerateNew
Id
(),
Time
=
tillTime
,
tcs
=
tcs
};
Timer
timer
=
new
Timer
{
Id
=
IdGenerater
.
Generate
Id
(),
Time
=
tillTime
,
tcs
=
tcs
};
this
.
timers
[
timer
.
Id
]
=
timer
;
this
.
timeId
.
Add
(
timer
.
Time
,
timer
.
Id
);
cancellationToken
.
Register
(()
=>
...
...
@@ -93,7 +89,7 @@ namespace Model
public
Task
WaitTillAsync
(
long
tillTime
)
{
TaskCompletionSource
<
bool
>
tcs
=
new
TaskCompletionSource
<
bool
>();
Timer
timer
=
new
Timer
{
Id
=
ObjectId
.
GenerateNew
Id
(),
Time
=
tillTime
,
tcs
=
tcs
};
Timer
timer
=
new
Timer
{
Id
=
IdGenerater
.
Generate
Id
(),
Time
=
tillTime
,
tcs
=
tcs
};
this
.
timers
[
timer
.
Id
]
=
timer
;
this
.
timeId
.
Add
(
timer
.
Time
,
timer
.
Id
);
return
tcs
.
Task
;
...
...
@@ -104,7 +100,7 @@ namespace Model
TaskCompletionSource
<
bool
>
tcs
=
new
TaskCompletionSource
<
bool
>();
Timer
timer
=
new
Timer
{
Id
=
ObjectId
.
GenerateNew
Id
(),
Id
=
IdGenerater
.
Generate
Id
(),
Time
=
TimeHelper
.
Now
()
+
time
,
tcs
=
tcs
};
...
...
@@ -122,7 +118,7 @@ namespace Model
TaskCompletionSource
<
bool
>
tcs
=
new
TaskCompletionSource
<
bool
>();
Timer
timer
=
new
Timer
{
Id
=
ObjectId
.
GenerateNew
Id
(),
Id
=
IdGenerater
.
Generate
Id
(),
Time
=
TimeHelper
.
Now
()
+
time
,
tcs
=
tcs
};
...
...
Unity/Assets/Scripts/Helper.meta
0 → 100644
浏览文件 @
707e1d16
fileFormatVersion: 2
guid: 750b9e7f02770174ba6d2e9aa59d68ae
folderAsset: yes
timeCreated: 1476935213
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
Unity/Assets/Scripts/Helper/DllHelper.cs
0 → 100644
浏览文件 @
707e1d16
using
System.Reflection
;
using
UnityEngine
;
namespace
Model
{
public
static
class
DllHelper
{
public
static
Assembly
GetController
()
{
GameObject
code
=
(
GameObject
)
Resources
.
Load
(
"Code"
);
byte
[]
assBytes
=
code
.
Get
<
TextAsset
>(
"Controller.dll"
).
bytes
;
byte
[]
mdbBytes
=
code
.
Get
<
TextAsset
>(
"Controller.dll.mdb"
).
bytes
;
Assembly
assembly
=
Assembly
.
Load
(
assBytes
,
mdbBytes
);
return
assembly
;
}
}
}
Unity/Assets/Scripts/Helper/DllHelper.cs.meta
0 → 100644
浏览文件 @
707e1d16
fileFormatVersion: 2
guid: 1e547a91aff347f4391ed7bc7e00ef63
timeCreated: 1476935213
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Unity/Assets/Scripts/Init.cs
浏览文件 @
707e1d16
...
...
@@ -11,12 +11,7 @@ namespace Model
{
Object
.
ObjectManager
.
Register
(
"Base"
,
typeof
(
Game
).
Assembly
);
Object
.
ObjectManager
.
Register
(
"Model"
,
typeof
(
Init
).
Assembly
);
GameObject
code
=
(
GameObject
)
Resources
.
Load
(
"Code"
);
byte
[]
assBytes
=
code
.
Get
<
TextAsset
>(
"Controller.dll"
).
bytes
;
byte
[]
mdbBytes
=
code
.
Get
<
TextAsset
>(
"Controller.dll.mdb"
).
bytes
;
Assembly
assembly
=
Assembly
.
Load
(
assBytes
,
mdbBytes
);
Object
.
ObjectManager
.
Register
(
"Controller"
,
assembly
);
Object
.
ObjectManager
.
Register
(
"Controller"
,
DllHelper
.
GetController
());
Game
.
Scene
.
AddComponent
<
EventComponent
>().
Run
(
EventIdType
.
InitSceneStart
);
}
...
...
Unity/Assets/Scripts/Message/AppType.cs
浏览文件 @
707e1d16
...
...
@@ -5,6 +5,7 @@
public
const
string
Client
=
"Client"
;
public
const
string
Robot
=
"Robot"
;
public
const
string
Manager
=
"Manager"
;
public
const
string
Realm
=
"Realm"
;
public
const
string
Gate
=
"Gate"
;
}
...
...
Unity/Assets/Scripts/Other/CommandLine.cs
浏览文件 @
707e1d16
using
System
;
using
System.Collections.Generic
;
using
Base
;
using
Model
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
MongoDB.Bson.Serialization.Attributes
;
namespace
Model
{
public
class
CommandLine
:
ICloneabl
e
public
class
CommandLine
s
:
ISupportInitializ
e
{
public
string
IP
=
""
;
public
Options
Options
=
new
Options
();
[
BsonIgnore
]
public
Options
Manager
{
get
;
private
set
;
}
public
object
Clone
()
[
BsonIgnore
]
public
Options
Realm
{
get
;
private
set
;
}
public
List
<
Options
>
Options
=
new
List
<
Options
>();
public
void
BeginInit
()
{
return
MongoHelper
.
FromBson
<
CommandLine
>(
MongoHelper
.
ToBson
(
this
));
}
}
public
class
CommandLines
{
public
List
<
CommandLine
>
Commands
=
new
List
<
CommandLine
>();
public
void
EndInit
()
{
foreach
(
Options
options
in
this
.
Options
)
{
if
(
options
.
AppType
==
AppType
.
Realm
)
{
this
.
Realm
=
options
;
}
if
(
options
.
AppType
==
AppType
.
Manager
)
{
this
.
Manager
=
options
;
}
}
}
}
}
Unity/Assets/Scripts/Other/Options.cs
浏览文件 @
707e1d16
using
System.Text
;
using
System
;
using
System.Text
;
using
Base
;
#if SERVER
using
CommandLine
;
...
...
@@ -6,17 +7,22 @@ using CommandLine;
namespace
Model
{
public
class
Options
public
class
Options
:
ICloneable
{
#if SERVER
[
Option
(
"
appType"
,
Required
=
true
,
HelpText
=
"AppType: realm gate
"
)]
[
Option
(
"
id"
,
Required
=
true
,
HelpText
=
"Id.
"
)]
#endif
public
string
AppType
{
get
;
set
;
}
public
int
Id
{
get
;
set
;
}
#if SERVER
[
Option
(
"
id"
,
Required
=
true
,
HelpText
=
"Id
."
)]
[
Option
(
"
IP"
,
Required
=
false
,
HelpText
=
"进程运行的服务器ip
."
)]
#endif
public
int
Id
{
get
;
set
;
}
public
string
IP
{
get
;
set
;
}
#if SERVER
[
Option
(
"appType"
,
Required
=
true
,
HelpText
=
"AppType: realm gate"
)]
#endif
public
string
AppType
{
get
;
set
;
}
#if SERVER
[
Option
(
"protocol"
,
Required
=
false
,
HelpText
=
"Protocol, tcp or udp."
,
DefaultValue
=
NetworkProtocol
.
UDP
)]
...
...
@@ -59,5 +65,10 @@ namespace Model
usage
.
AppendLine
(
"Read user manual for usage instructions..."
);
return
usage
.
ToString
();
}
public
object
Clone
()
{
return
MongoHelper
.
FromBson
<
Options
>(
MongoHelper
.
ToBson
(
this
));
}
}
}
\ No newline at end of file
Unity/Controller/Event/InitSceneStartEvent_InitGame.cs
浏览文件 @
707e1d16
...
...
@@ -14,7 +14,7 @@ namespace Controller
{
Game
.
Scene
.
AddComponent
<
MessageDispatherComponent
,
string
>(
"Client"
);
NetworkComponent
networkComponent
=
Game
.
Scene
.
AddComponent
<
NetworkComponent
,
NetworkProtocol
>(
NetworkProtocol
.
TCP
);
Entity
session
=
networkComponent
.
Get
(
"127.0.0.1:
8888
"
);
Entity
session
=
networkComponent
.
Get
(
"127.0.0.1:
10001
"
);
try
{
...
...
Unity/Unity.CSharp.Plugins.csproj
浏览文件 @
707e1d16
...
...
@@ -92,6 +92,7 @@
<Compile
Include=
"Assets\Plugins\Base\Helper\IdGenerater.cs"
/>
<Compile
Include=
"Assets\Plugins\Base\Helper\MD5Helper.cs"
/>
<Compile
Include=
"Assets\Plugins\Base\Helper\MongoHelper.cs"
/>
<Compile
Include=
"Assets\Plugins\Base\Helper\NetHelper.cs"
/>
<Compile
Include=
"Assets\Plugins\Base\Helper\ProtobufHelper.cs"
/>
<Compile
Include=
"Assets\Plugins\Base\Helper\RandomHelper.cs"
/>
<Compile
Include=
"Assets\Plugins\Base\Helper\StringHelper.cs"
/>
...
...
Unity/Unity.CSharp.csproj
浏览文件 @
707e1d16
...
...
@@ -83,7 +83,6 @@
<Compile
Include=
"Assets\Scripts\Component\EventComponent.cs"
/>
<Compile
Include=
"Assets\Scripts\Component\GameObjectComponent.cs"
/>
<Compile
Include=
"Assets\Scripts\Component\GlobalConfigComponent.cs"
/>
<Compile
Include=
"Assets\Scripts\Component\AppInfoComponent.cs"
/>
<Compile
Include=
"Assets\Scripts\Component\KVComponent.cs"
/>
<Compile
Include=
"Assets\Scripts\Component\MessageComponent.cs"
/>
<Compile
Include=
"Assets\Scripts\Component\MessageDispatherComponent.cs"
/>
...
...
@@ -97,6 +96,7 @@
<Compile
Include=
"Assets\Scripts\Event\EnvKey.cs"
/>
<Compile
Include=
"Assets\Scripts\Event\EventIdType.cs"
/>
<Compile
Include=
"Assets\Scripts\GameObjectHelper.cs"
/>
<Compile
Include=
"Assets\Scripts\Helper\DllHelper.cs"
/>
<Compile
Include=
"Assets\Scripts\Init.cs"
/>
<Compile
Include=
"Assets\Scripts\Message\AppType.cs"
/>
<Compile
Include=
"Assets\Scripts\Message\ErrorCode.cs"
/>
...
...
@@ -113,5 +113,6 @@
<None
Include=
"Assets\CSharp 6.0 Support\AsyncTools\Plugins\AsyncBridge.Net35.xml"
/>
<None
Include=
"Assets\CSharp 6.0 Support\AsyncTools\Plugins\System.Threading.xml"
/>
</ItemGroup>
<ItemGroup
/>
<Import
Project=
"$(MSBuildExtensionsPath)\SyntaxTree\UnityVS\2015\UnityVS.CSharp.targets"
/>
</Project>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录