Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
老鱼er
et
提交
1d1b0499
E
et
项目概览
老鱼er
/
et
与 Fork 源项目一致
从无法访问的项目Fork
通知
10
Star
1
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,发现更多精彩内容 >>
提交
1d1b0499
编写于
10月 19, 2016
作者:
T
tanghai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
重新设计了RPC服务端代码,使用起来更简单更不容易出错
上级
05b2758d
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
152 addition
and
77 deletion
+152
-77
Server/App/Program.cs
Server/App/Program.cs
+1
-1
Server/Base/Server.Base.csproj
Server/Base/Server.Base.csproj
+3
-3
Server/Controller/C2S_LoginHandler.cs
Server/Controller/C2S_LoginHandler.cs
+17
-0
Server/Controller/C2S_SubscribeLogHandler.cs
Server/Controller/C2S_SubscribeLogHandler.cs
+5
-4
Server/Controller/Server.Controller.csproj
Server/Controller/Server.Controller.csproj
+2
-2
Server/Model/Component/LogToClientComponent.cs
Server/Model/Component/LogToClientComponent.cs
+4
-1
Server/Model/Server.Model.csproj
Server/Model/Server.Model.csproj
+3
-0
Unity/Assets/Plugins/Base/Message/AMEvent.cs
Unity/Assets/Plugins/Base/Message/AMEvent.cs
+13
-9
Unity/Assets/Plugins/Base/Message/AMessage.cs
Unity/Assets/Plugins/Base/Message/AMessage.cs
+0
-3
Unity/Assets/Plugins/Base/Message/AMessage.cs.meta
Unity/Assets/Plugins/Base/Message/AMessage.cs.meta
+0
-0
Unity/Assets/Plugins/Base/Message/IMRegister.cs
Unity/Assets/Plugins/Base/Message/IMRegister.cs
+5
-2
Unity/Assets/Scripts/Component/AppInfoComponent.cs
Unity/Assets/Scripts/Component/AppInfoComponent.cs
+23
-0
Unity/Assets/Scripts/Component/AppInfoComponent.cs.meta
Unity/Assets/Scripts/Component/AppInfoComponent.cs.meta
+12
-0
Unity/Assets/Scripts/Component/MessageComponent.cs
Unity/Assets/Scripts/Component/MessageComponent.cs
+21
-12
Unity/Assets/Scripts/Component/MessageDispatherComponent.cs
Unity/Assets/Scripts/Component/MessageDispatherComponent.cs
+36
-35
Unity/Assets/Scripts/Message/Message.cs
Unity/Assets/Scripts/Message/Message.cs
+2
-1
Unity/Controller/Message/S2C_ServerLogHandler.cs
Unity/Controller/Message/S2C_ServerLogHandler.cs
+2
-2
Unity/Controller/Unity.Controller.csproj
Unity/Controller/Unity.Controller.csproj
+1
-1
Unity/Unity.CSharp.Plugins.csproj
Unity/Unity.CSharp.Plugins.csproj
+1
-1
Unity/Unity.CSharp.csproj
Unity/Unity.CSharp.csproj
+1
-0
未找到文件。
Server/App/Program.cs
浏览文件 @
1d1b0499
...
...
@@ -23,7 +23,7 @@ namespace App
Object
.
ObjectManager
.
Register
(
"Controller"
,
controller
);
Options
options
=
Game
.
Scene
.
AddComponent
<
OptionsComponent
,
string
[
]>
(
args
).
Options
;
Game
.
Scene
.
AddComponent
<
EventComponent
>();
Game
.
Scene
.
AddComponent
<
TimerComponent
>();
Game
.
Scene
.
AddComponent
<
NetworkComponent
,
NetworkProtocol
,
string
,
int
>(
options
.
Protocol
,
options
.
Host
,
options
.
Port
);
...
...
Server/Base/Server.Base.csproj
浏览文件 @
1d1b0499
...
...
@@ -122,12 +122,12 @@
<Compile
Include=
"..\..\Unity\Assets\Plugins\Base\LogType.cs"
>
<Link>
LogType.cs
</Link>
</Compile>
<Compile
Include=
"..\..\Unity\Assets\Plugins\Base\Message\AMessage.cs"
>
<Link>
Message\AMessage.cs
</Link>
</Compile>
<Compile
Include=
"..\..\Unity\Assets\Plugins\Base\Message\AMEvent.cs"
>
<Link>
Message\AMEvent.cs
</Link>
</Compile>
<Compile
Include=
"..\..\Unity\Assets\Plugins\Base\Message\IErrorMessage.cs"
>
<Link>
Message\IErrorMessage.cs
</Link>
</Compile>
<Compile
Include=
"..\..\Unity\Assets\Plugins\Base\Message\IMRegister.cs"
>
<Link>
Message\IMRegister.cs
</Link>
</Compile>
...
...
Server/Controller/C2S_Login
Event
.cs
→
Server/Controller/C2S_Login
Handler
.cs
浏览文件 @
1d1b0499
using
Base
;
using
System
;
using
Base
;
using
Model
;
namespace
Controller
{
[
MessageHandler
(
AppType
.
Realm
)]
public
class
C2S_Login
Event
:
AMRpcEvent
<
C2S
_Login
>
public
class
C2S_Login
Handler
:
AMRpcEvent
<
C2S_Login
,
S2C
_Login
>
{
protected
override
void
Run
(
Entity
scene
,
C2S_Login
message
,
uint
rpcId
)
protected
override
void
Run
(
Entity
scene
,
C2S_Login
message
,
Action
<
S2C_Login
>
reply
)
{
Log
.
Info
(
MongoHelper
.
ToJson
(
message
));
scene
.
GetComponent
<
MessageComponent
>().
Reply
(
rpcId
,
new
S2C_Login
());
reply
(
new
S2C_Login
());
}
}
}
\ No newline at end of file
Server/Controller/C2S_SubscribeLog
Event
.cs
→
Server/Controller/C2S_SubscribeLog
Handler
.cs
浏览文件 @
1d1b0499
using
Base
;
using
System
;
using
Base
;
using
Model
;
namespace
Controller
{
[
MessageHandler
(
AppType
.
Realm
)]
public
class
C2S_SubscribeLog
Event
:
AMRpcEvent
<
C2S
_SubscribeLog
>
public
class
C2S_SubscribeLog
Handler
:
AMRpcEvent
<
C2S_SubscribeLog
,
S2C
_SubscribeLog
>
{
protected
override
void
Run
(
Entity
entity
,
C2S_SubscribeLog
message
,
uint
rpcId
)
protected
override
void
Run
(
Entity
entity
,
C2S_SubscribeLog
message
,
Action
<
S2C_SubscribeLog
>
reply
)
{
Log
.
Info
(
MongoHelper
.
ToJson
(
message
));
entity
.
AddComponent
<
LogToClientComponent
>();
entity
.
GetComponent
<
MessageComponent
>().
Reply
(
rpcId
,
new
S2C_SubscribeLog
());
reply
(
new
S2C_SubscribeLog
());
}
}
}
\ No newline at end of file
Server/Controller/Server.Controller.csproj
浏览文件 @
1d1b0499
...
...
@@ -34,9 +34,9 @@
<Reference
Include=
"System.Core"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"C2S_SubscribeLog
Event
.cs"
/>
<Compile
Include=
"C2S_SubscribeLog
Handler
.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"C2S_Login
Event
.cs"
/>
<Compile
Include=
"C2S_Login
Handler
.cs"
/>
</ItemGroup>
<ItemGroup>
<ProjectReference
Include=
"..\Base\Server.Base.csproj"
>
...
...
Server/Model/Component/LogToClientComponent.cs
浏览文件 @
1d1b0499
...
...
@@ -13,8 +13,11 @@ namespace Model
public
class
LogToClientComponent
:
Component
{
private
string
appType
;
public
void
Awake
()
{
this
.
appType
=
Game
.
Scene
.
GetComponent
<
OptionsComponent
>().
Options
.
AppType
;
Log
.
Callback
.
Add
(
this
.
Id
,
this
.
LogToClient
);
}
...
...
@@ -24,7 +27,7 @@ namespace Model
{
return
;
}
this
.
GetComponent
<
MessageComponent
>().
Send
(
new
S2C_ServerLog
{
Type
=
type
,
Log
=
message
});
this
.
GetComponent
<
MessageComponent
>().
Send
(
new
S2C_ServerLog
{
AppType
=
this
.
appType
,
Type
=
type
,
Log
=
message
});
}
public
override
void
Dispose
()
...
...
Server/Model/Server.Model.csproj
浏览文件 @
1d1b0499
...
...
@@ -41,6 +41,9 @@
<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>
...
...
Unity/Assets/Plugins/Base/Message/AMEvent.cs
浏览文件 @
1d1b0499
namespace
Base
using
System
;
namespace
Base
{
public
abstract
class
AMEvent
<
T
>:
IMRegister
public
abstract
class
AMEvent
<
Message
>:
IMRegister
where
Message
:
AMessage
{
protected
abstract
void
Run
(
Entity
scene
,
T
message
);
protected
abstract
void
Run
(
Entity
scene
,
Message
message
);
public
void
Register
(
IMessageDispather
component
)
{
ushort
opcode
=
component
.
GetOpcode
(
typeof
(
T
));
component
.
RegisterHandler
<
T
>(
opcode
,
Run
);
ushort
opcode
=
component
.
GetOpcode
(
typeof
(
Message
));
component
.
RegisterHandler
<
Message
>(
opcode
,
Run
);
}
}
public
abstract
class
AMRpcEvent
<
T
>
:
IMRegister
public
abstract
class
AMRpcEvent
<
Request
,
Response
>
:
IMRegister
where
Request
:
ARequest
where
Response
:
AResponse
{
protected
abstract
void
Run
(
Entity
scene
,
T
message
,
uint
rpcId
);
protected
abstract
void
Run
(
Entity
scene
,
Request
message
,
Action
<
Response
>
reply
);
public
void
Register
(
IMessageDispather
component
)
{
ushort
opcode
=
component
.
GetOpcode
(
typeof
(
T
));
component
.
RegisterRpcHandler
<
T
>(
opcode
,
Run
);
ushort
opcode
=
component
.
GetOpcode
(
typeof
(
Request
));
component
.
RegisterRpcHandler
<
Request
,
Response
>(
opcode
,
Run
);
}
}
}
\ No newline at end of file
Unity/Assets/Plugins/Base/Message/
IError
Message.cs
→
Unity/Assets/Plugins/Base/Message/
A
Message.cs
浏览文件 @
1d1b0499
...
...
@@ -6,7 +6,6 @@
public
abstract
class
ARequest
:
AMessage
{
public
uint
RpcId
;
}
/// <summary>
...
...
@@ -14,8 +13,6 @@
/// </summary>
public
abstract
class
AResponse
:
AMessage
{
public
uint
RpcId
;
public
int
ErrorCode
=
0
;
public
string
Message
=
""
;
}
...
...
Unity/Assets/Plugins/Base/Message/
IError
Message.cs.meta
→
Unity/Assets/Plugins/Base/Message/
A
Message.cs.meta
浏览文件 @
1d1b0499
文件已移动
Unity/Assets/Plugins/Base/Message/IMRegister.cs
浏览文件 @
1d1b0499
...
...
@@ -5,8 +5,11 @@ namespace Base
public
interface
IMessageDispather
{
ushort
GetOpcode
(
Type
type
);
void
RegisterHandler
<
T
>(
ushort
opcode
,
Action
<
Entity
,
T
>
action
);
void
RegisterRpcHandler
<
T
>(
ushort
opcode
,
Action
<
Entity
,
T
,
uint
>
action
);
void
RegisterHandler
<
Message
>(
ushort
opcode
,
Action
<
Entity
,
Message
>
action
)
where
Message
:
AMessage
;
void
RegisterRpcHandler
<
Request
,
Response
>(
ushort
opcode
,
Action
<
Entity
,
Request
,
Action
<
Response
>>
action
)
where
Request
:
ARequest
where
Response
:
AResponse
;
}
public
interface
IMRegister
...
...
Unity/Assets/Scripts/Component/AppInfoComponent.cs
0 → 100644
浏览文件 @
1d1b0499
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/AppInfoComponent.cs.meta
0 → 100644
浏览文件 @
1d1b0499
fileFormatVersion: 2
guid: d4852a0f714d73f43af0109603bd32ba
timeCreated: 1476849603
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Unity/Assets/Scripts/Component/MessageComponent.cs
浏览文件 @
1d1b0499
...
...
@@ -99,20 +99,24 @@ namespace Model
private
void
RunDecompressedBytes
(
ushort
opcode
,
uint
rpcId
,
uint
rpcFlag
,
byte
[]
messageBytes
,
int
offset
)
{
// 普通消息
if
(
rpcId
==
0
)
{
this
.
messageDispather
.
Handle
(
this
.
Owner
,
opcode
,
messageBytes
,
offset
);
return
;
}
// rpcFlag>0 表示这是一个rpc响应消息
if
(
rpcFlag
>
0
)
{
Action
<
byte
[],
int
,
int
>
action
;
if
(
this
.
requestCallback
.
TryGetValue
(
rpcId
,
out
action
))
// Rpc回调有找不着的可能,因为client可能取消Rpc调用
if
(!
this
.
requestCallback
.
TryGetValue
(
rpcId
,
out
action
))
{
this
.
requestCallback
.
Remove
(
rpcId
);
action
(
messageBytes
,
offset
,
messageBytes
.
Length
-
offset
);
return
;
}
this
.
requestCallback
.
Remove
(
rpcId
);
action
(
messageBytes
,
offset
,
messageBytes
.
Length
-
offset
);
}
else
// 这是一个rpc请求消息
{
...
...
@@ -161,7 +165,6 @@ namespace Model
where
Request
:
ARequest
where
Response
:
AResponse
{
request
.
RpcId
=
++
RpcId
;
this
.
SendMessage
(++
RpcId
,
request
);
var
tcs
=
new
TaskCompletionSource
<
Response
>();
this
.
requestCallback
[
RpcId
]
=
(
bytes
,
offset
,
count
)
=>
...
...
@@ -185,12 +188,12 @@ namespace Model
return
tcs
.
Task
;
}
public
void
Send
(
object
message
)
public
void
Send
<
Message
>(
Message
message
)
where
Message
:
AMessage
{
this
.
SendMessage
(
0
,
message
);
}
public
void
Reply
<
T
>(
uint
rpcId
,
T
message
)
where
T
:
AResponse
public
void
Reply
<
Response
>(
uint
rpcId
,
Response
message
)
where
Response
:
AResponse
{
this
.
SendMessage
(
rpcId
,
message
,
false
);
}
...
...
@@ -199,18 +202,24 @@ namespace Model
{
ushort
opcode
=
this
.
messageDispather
.
GetOpcode
(
message
.
GetType
());
byte
[]
opcodeBytes
=
BitConverter
.
GetBytes
(
opcode
);
if
(
rpcId
>
0
&&
!
isCall
)
if
(!
isCall
)
{
rpcId
=
rpcId
|
0x4
fffffff
;
rpcId
=
rpcId
|
0x4
0000000
;
}
byte
[]
seqBytes
=
BitConverter
.
GetBytes
(
rpcId
);
byte
[]
messageBytes
=
MongoHelper
.
ToBson
(
message
);
if
(
channel
==
null
)
byte
[]
messageBytes
=
MongoHelper
.
ToBson
(
message
);
if
(
messageBytes
.
Length
>
100
)
{
throw
new
Exception
(
"game channel not found!"
);
byte
[]
newMessageBytes
=
ZipHelper
.
Compress
(
messageBytes
);
if
(
newMessageBytes
.
Length
<
messageBytes
.
Length
)
{
messageBytes
=
newMessageBytes
;
rpcId
=
rpcId
|
0x80000000
;
}
}
byte
[]
seqBytes
=
BitConverter
.
GetBytes
(
rpcId
);
channel
.
Send
(
new
List
<
byte
[
]>
{
opcodeBytes
,
seqBytes
,
messageBytes
});
}
...
...
Unity/Assets/Scripts/Component/MessageDispatherComponent.cs
浏览文件 @
1d1b0499
...
...
@@ -35,9 +35,9 @@ namespace Model
}
private
string
AppType
;
private
Dictionary
<
ushort
,
List
<
Action
<
Entity
,
MessageInfo
>>>
event
s
;
private
Dictionary
<
ushort
,
List
<
Action
<
Entity
,
MessageInfo
>
>>
rpcHandlers
;
p
ublic
Dictionary
<
Type
,
MessageAttribute
>
messageOpcode
{
get
;
private
set
;
}
=
new
Dictionary
<
Type
,
MessageAttribute
>();
private
Dictionary
<
ushort
,
List
<
Action
<
Entity
,
MessageInfo
>>>
handler
s
;
private
Dictionary
<
ushort
,
Action
<
Entity
,
MessageInfo
>>
rpcHandlers
;
p
rivate
Dictionary
<
Type
,
MessageAttribute
>
messageOpcode
{
get
;
set
;
}
=
new
Dictionary
<
Type
,
MessageAttribute
>();
public
void
Awake
(
string
appType
)
{
...
...
@@ -47,8 +47,8 @@ namespace Model
public
void
Load
()
{
this
.
event
s
=
new
Dictionary
<
ushort
,
List
<
Action
<
Entity
,
MessageInfo
>>>();
this
.
rpcHandlers
=
new
Dictionary
<
ushort
,
List
<
Action
<
Entity
,
MessageInfo
>
>>();
this
.
handler
s
=
new
Dictionary
<
ushort
,
List
<
Action
<
Entity
,
MessageInfo
>>>();
this
.
rpcHandlers
=
new
Dictionary
<
ushort
,
Action
<
Entity
,
MessageInfo
>>();
this
.
messageOpcode
=
new
Dictionary
<
Type
,
MessageAttribute
>();
Assembly
[]
assemblies
=
Object
.
ObjectManager
.
GetAssemblies
();
...
...
@@ -91,7 +91,7 @@ namespace Model
IMRegister
iMRegister
=
obj
as
IMRegister
;
if
(
iMRegister
==
null
)
{
throw
new
Exception
(
$"message handler not inherit
IEventSync or IEventAsync interface
:
{
obj
.
GetType
().
FullName
}
"
);
throw
new
Exception
(
$"message handler not inherit
AMEvent or AMRpcEvent abstract class
:
{
obj
.
GetType
().
FullName
}
"
);
}
iMRegister
.
Register
(
this
);
}
...
...
@@ -103,51 +103,55 @@ namespace Model
return
this
.
messageOpcode
[
type
].
Opcode
;
}
public
void
RegisterHandler
<
T
>(
ushort
opcode
,
Action
<
Entity
,
T
>
action
)
public
void
RegisterHandler
<
Message
>(
ushort
opcode
,
Action
<
Entity
,
Message
>
action
)
where
Message
:
AMessage
{
if
(!
this
.
event
s
.
ContainsKey
(
opcode
))
if
(!
this
.
handler
s
.
ContainsKey
(
opcode
))
{
this
.
event
s
.
Add
(
opcode
,
new
List
<
Action
<
Entity
,
MessageInfo
>>());
this
.
handler
s
.
Add
(
opcode
,
new
List
<
Action
<
Entity
,
MessageInfo
>>());
}
List
<
Action
<
Entity
,
MessageInfo
>>
actions
=
this
.
event
s
[
opcode
];
List
<
Action
<
Entity
,
MessageInfo
>>
actions
=
this
.
handler
s
[
opcode
];
actions
.
Add
((
entity
,
messageInfo
)
=>
{
T
t
;
Message
message
;
try
{
t
=
MongoHelper
.
FromBson
<
T
>(
messageInfo
.
MessageBytes
,
messageInfo
.
Offset
,
messageInfo
.
Count
);
message
=
MongoHelper
.
FromBson
<
Message
>(
messageInfo
.
MessageBytes
,
messageInfo
.
Offset
,
messageInfo
.
Count
);
}
catch
(
Exception
ex
)
{
throw
new
Exception
(
"解释消息失败:"
+
opcode
,
ex
);
}
action
(
entity
,
t
);
action
(
entity
,
message
);
});
}
public
void
RegisterRpcHandler
<
T
>(
ushort
opcode
,
Action
<
Entity
,
T
,
uint
>
action
)
public
void
RegisterRpcHandler
<
Request
,
Response
>(
ushort
opcode
,
Action
<
Entity
,
Request
,
Action
<
Response
>>
action
)
where
Request
:
ARequest
where
Response
:
AResponse
{
if
(
!
this
.
rpcHandlers
.
ContainsKey
(
opcode
))
if
(
this
.
rpcHandlers
.
ContainsKey
(
opcode
))
{
this
.
rpcHandlers
.
Add
(
opcode
,
new
List
<
Action
<
Entity
,
MessageInfo
>>());
Log
.
Error
(
$"rpc消息不能注册两次! opcode:
{
opcode
}
"
);
return
;
}
List
<
Action
<
Entity
,
MessageInfo
>>
actions
=
this
.
rpcHandlers
[
opcode
];
actions
.
Add
((
entity
,
messageInfo
)
=>
this
.
rpcHandlers
.
Add
(
opcode
,
(
entity
,
messageInfo
)
=>
{
T
t
;
Request
reques
t
;
try
{
t
=
MongoHelper
.
FromBson
<
T
>(
messageInfo
.
MessageBytes
,
messageInfo
.
Offset
,
messageInfo
.
Count
);
request
=
MongoHelper
.
FromBson
<
Request
>(
messageInfo
.
MessageBytes
,
messageInfo
.
Offset
,
messageInfo
.
Count
);
}
catch
(
Exception
ex
)
{
throw
new
Exception
(
"解释消息失败:"
+
opcode
,
ex
);
}
action
(
entity
,
t
,
messageInfo
.
RpcId
);
action
(
entity
,
request
,
response
=>
{
entity
.
GetComponent
<
MessageComponent
>().
Reply
(
messageInfo
.
RpcId
,
response
);
});
});
}
...
...
@@ -155,7 +159,7 @@ namespace Model
public
void
Handle
(
Entity
entity
,
ushort
opcode
,
byte
[]
messageBytes
,
int
offset
)
{
List
<
Action
<
Entity
,
MessageInfo
>>
actions
;
if
(!
this
.
event
s
.
TryGetValue
(
opcode
,
out
actions
))
if
(!
this
.
handler
s
.
TryGetValue
(
opcode
,
out
actions
))
{
Log
.
Error
(
$"消息
{
opcode
}
没有处理"
);
return
;
...
...
@@ -176,23 +180,20 @@ namespace Model
public
void
HandleRpc
(
Entity
entity
,
ushort
opcode
,
byte
[]
messageBytes
,
int
offset
,
uint
rpcId
)
{
List
<
Action
<
Entity
,
MessageInfo
>>
actions
;
if
(!
this
.
rpcHandlers
.
TryGetValue
(
opcode
,
out
action
s
))
Action
<
Entity
,
MessageInfo
>
action
;
if
(!
this
.
rpcHandlers
.
TryGetValue
(
opcode
,
out
action
))
{
Log
.
Error
(
$"Rpc消息
{
opcode
}
没有处理"
);
return
;
}
foreach
(
var
ev
in
actions
)
try
{
try
{
ev
(
entity
,
new
MessageInfo
{
MessageBytes
=
messageBytes
,
Offset
=
offset
,
Count
=
messageBytes
.
Length
-
offset
,
RpcId
=
rpcId
});
}
catch
(
Exception
e
)
{
Log
.
Error
(
e
.
ToString
());
}
action
(
entity
,
new
MessageInfo
{
MessageBytes
=
messageBytes
,
Offset
=
offset
,
Count
=
messageBytes
.
Length
-
offset
,
RpcId
=
rpcId
});
}
catch
(
Exception
e
)
{
Log
.
Error
(
e
.
ToString
());
}
}
...
...
Unity/Assets/Scripts/Message/Message.cs
浏览文件 @
1d1b0499
...
...
@@ -21,8 +21,9 @@ namespace Model
[
Message
(
3
)]
[
BsonIgnoreExtraElements
]
public
class
S2C_ServerLog
public
class
S2C_ServerLog
:
AMessage
{
public
string
AppType
;
public
LogType
Type
;
public
string
Log
;
}
...
...
Unity/Controller/Message/S2C_ServerLog
Event
.cs
→
Unity/Controller/Message/S2C_ServerLog
Handler
.cs
浏览文件 @
1d1b0499
...
...
@@ -4,11 +4,11 @@ using Model;
namespace
Controller
{
[
MessageHandler
(
AppType
.
Client
)]
public
class
S2C_ServerLog
Event
:
AMEvent
<
S2C_ServerLog
>
public
class
S2C_ServerLog
Handler
:
AMEvent
<
S2C_ServerLog
>
{
protected
override
void
Run
(
Entity
scene
,
S2C_ServerLog
message
)
{
Log
.
Debug
(
message
.
Log
);
Log
.
Debug
(
$"[
{
message
.
AppType
}
] [
{
message
.
Type
}
]
{
message
.
Log
}
"
);
}
}
}
Unity/Controller/Unity.Controller.csproj
浏览文件 @
1d1b0499
...
...
@@ -54,7 +54,7 @@
</ItemGroup>
<ItemGroup>
<Compile
Include=
"Event\InitSceneStartEvent_InitGame.cs"
/>
<Compile
Include=
"Message\S2C_ServerLog
Event
.cs"
/>
<Compile
Include=
"Message\S2C_ServerLog
Handler
.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
<ItemGroup>
...
...
Unity/Unity.CSharp.Plugins.csproj
浏览文件 @
1d1b0499
...
...
@@ -100,7 +100,7 @@
<Compile
Include=
"Assets\Plugins\Base\Log.cs"
/>
<Compile
Include=
"Assets\Plugins\Base\LogType.cs"
/>
<Compile
Include=
"Assets\Plugins\Base\Message\AMEvent.cs"
/>
<Compile
Include=
"Assets\Plugins\Base\Message\
IError
Message.cs"
/>
<Compile
Include=
"Assets\Plugins\Base\Message\
A
Message.cs"
/>
<Compile
Include=
"Assets\Plugins\Base\Message\IMRegister.cs"
/>
<Compile
Include=
"Assets\Plugins\Base\Message\MessageHandlerAttribute.cs"
/>
<Compile
Include=
"Assets\Plugins\Base\Message\MessageAttribute.cs"
/>
...
...
Unity/Unity.CSharp.csproj
浏览文件 @
1d1b0499
...
...
@@ -83,6 +83,7 @@
<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"
/>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录