Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
老鱼er
et
提交
69d0ef37
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,体验更适合开发者的 AI 搜索 >>
提交
69d0ef37
编写于
8月 25, 2017
作者:
T
tanghai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1.location完善了lock unlock调用,location保存到mongodb中
2.actor消息一个个处理,处理完一个才处理下一个
上级
bbd76565
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
108 addition
and
40 deletion
+108
-40
Server/Hotfix/Message/ObjectLockRequestHandler.cs
Server/Hotfix/Message/ObjectLockRequestHandler.cs
+1
-1
Server/Hotfix/Message/ObjectUnLockRequestHandler.cs
Server/Hotfix/Message/ObjectUnLockRequestHandler.cs
+1
-1
Server/Model/Component/ActorComponent.cs
Server/Model/Component/ActorComponent.cs
+1
-1
Server/Model/Component/ActorMessageDispatherComponent.cs
Server/Model/Component/ActorMessageDispatherComponent.cs
+4
-3
Server/Model/Component/LocationComponent.cs
Server/Model/Component/LocationComponent.cs
+48
-16
Server/Model/Component/LocationProxyComponent.cs
Server/Model/Component/LocationProxyComponent.cs
+17
-1
Server/Model/Entity/DBEntity.cs
Server/Model/Entity/DBEntity.cs
+1
-0
Server/Model/Entity/Location.cs
Server/Model/Entity/Location.cs
+12
-0
Server/Model/Entity/Message/InnerMessage.cs
Server/Model/Entity/Message/InnerMessage.cs
+2
-2
Server/Model/Message/AMActorHandler.cs
Server/Model/Message/AMActorHandler.cs
+11
-10
Server/Model/Message/IEntityActorHandler.cs
Server/Model/Message/IEntityActorHandler.cs
+7
-4
Server/Model/Message/IMActorHandler.cs
Server/Model/Message/IMActorHandler.cs
+2
-1
Server/Model/Server.Model.csproj
Server/Model/Server.Model.csproj
+1
-0
未找到文件。
Server/Hotfix/Message/ObjectLockRequestHandler.cs
浏览文件 @
69d0ef37
...
...
@@ -11,7 +11,7 @@ namespace Hotfix
ObjectLockResponse
response
=
new
ObjectLockResponse
();
try
{
Game
.
Scene
.
GetComponent
<
LocationComponent
>().
Add
(
message
.
Key
,
session
.
RemoteAddress
);
Game
.
Scene
.
GetComponent
<
LocationComponent
>().
LockAsync
(
message
.
Key
,
message
.
Time
);
reply
(
response
);
}
catch
(
Exception
e
)
...
...
Server/Hotfix/Message/ObjectUnLockRequestHandler.cs
浏览文件 @
69d0ef37
...
...
@@ -11,7 +11,7 @@ namespace Hotfix
ObjectUnLockResponse
response
=
new
ObjectUnLockResponse
();
try
{
Game
.
Scene
.
GetComponent
<
LocationComponent
>().
U
nLock
(
message
.
Key
,
message
.
Value
);
Game
.
Scene
.
GetComponent
<
LocationComponent
>().
U
pdateAndUnLock
(
message
.
Key
,
message
.
AppId
,
message
.
Value
);
reply
(
response
);
}
catch
(
Exception
e
)
...
...
Server/Model/Component/ActorComponent.cs
浏览文件 @
69d0ef37
...
...
@@ -79,7 +79,7 @@ namespace Model
while
(
true
)
{
ActorMessageInfo
info
=
await
this
.
GetAsync
();
this
.
entityActorHandler
.
Handle
(
info
.
Session
,
this
.
Owner
,
info
.
Message
);
await
this
.
entityActorHandler
.
Handle
(
info
.
Session
,
this
.
Owner
,
info
.
Message
);
}
}
...
...
Server/Model/Component/ActorMessageDispatherComponent.cs
浏览文件 @
69d0ef37
using
System
;
using
System.Collections.Generic
;
using
System.Threading.Tasks
;
namespace
Model
{
...
...
@@ -70,14 +71,14 @@ namespace Model
return
actorHandler
;
}
public
void
Handle
(
Session
session
,
Entity
entity
,
IActorMessage
message
)
public
async
Task
<
bool
>
Handle
(
Session
session
,
Entity
entity
,
IActorMessage
message
)
{
if
(!
this
.
handlers
.
TryGetValue
(
message
.
GetType
(),
out
IMActorHandler
handler
))
{
Log
.
Error
(
$"not found message handler:
{
message
.
GetType
().
FullName
}
"
);
return
;
return
false
;
}
handler
.
Handle
(
session
,
entity
,
message
);
return
await
handler
.
Handle
(
session
,
entity
,
message
);
}
public
override
void
Dispose
()
...
...
Server/Model/Component/LocationComponent.cs
浏览文件 @
69d0ef37
...
...
@@ -21,11 +21,14 @@ namespace Model
{
private
readonly
long
key
;
private
readonly
int
time
;
private
readonly
TaskCompletionSource
<
bool
>
tcs
;
public
LocationLockTask
(
long
key
)
public
LocationLockTask
(
long
key
,
int
time
)
{
this
.
key
=
key
;
this
.
time
=
time
;
this
.
tcs
=
new
TaskCompletionSource
<
bool
>();
}
...
...
@@ -41,7 +44,7 @@ namespace Model
{
try
{
Scene
.
GetComponent
<
LocationComponent
>().
Lock
(
this
.
key
);
Scene
.
GetComponent
<
LocationComponent
>().
Lock
(
this
.
key
,
this
.
time
);
this
.
tcs
.
SetResult
(
true
);
}
catch
(
Exception
e
)
...
...
@@ -89,13 +92,16 @@ namespace Model
{
private
readonly
Dictionary
<
long
,
string
>
locations
=
new
Dictionary
<
long
,
string
>();
private
readonly
HashSet
<
long
>
lockSet
=
new
HashSet
<
long
>();
private
readonly
Dictionary
<
long
,
int
>
lockDict
=
new
Dictionary
<
long
,
int
>();
private
readonly
Dictionary
<
long
,
Queue
<
LocationTask
>>
taskQueues
=
new
Dictionary
<
long
,
Queue
<
LocationTask
>>();
public
void
Add
(
long
key
,
string
address
)
public
async
void
Add
(
long
key
,
string
address
)
{
this
.
locations
[
key
]
=
address
;
// 更新db
await
Game
.
Scene
.
GetComponent
<
DBProxyComponent
>().
Save
(
new
Location
(
key
,
address
));
}
public
void
Remove
(
long
key
)
...
...
@@ -109,20 +115,46 @@ namespace Model
return
location
;
}
public
void
Lock
(
long
key
)
public
async
void
Lock
(
long
key
,
int
appId
,
int
time
=
0
)
{
if
(
this
.
lock
Set
.
Contains
(
key
))
if
(
this
.
lock
Dict
.
ContainsKey
(
key
))
{
return
;
}
this
.
lockSet
.
Add
(
key
);
this
.
lockDict
.
Add
(
key
,
appId
);
// 超时则解锁
if
(
time
>
0
)
{
await
Game
.
Scene
.
GetComponent
<
TimerComponent
>().
WaitAsync
(
time
);
int
saveAppId
=
0
;
this
.
lockDict
.
TryGetValue
(
key
,
out
saveAppId
);
if
(
saveAppId
!=
appId
)
{
Log
.
Warning
(
$"unlock appid is different
{
saveAppId
}
{
appId
}
"
);
return
;
}
this
.
UnLock
(
key
);
}
}
public
void
U
nLock
(
long
key
,
string
value
)
public
void
U
pdateAndUnLock
(
long
key
,
int
appId
,
string
value
)
{
this
.
lockSet
.
Remove
(
key
);
int
saveAppId
=
0
;
this
.
lockDict
.
TryGetValue
(
key
,
out
saveAppId
);
if
(
saveAppId
!=
appId
)
{
Log
.
Warning
(
$"unlock appid is different
{
saveAppId
}
{
appId
}
"
);
return
;
}
this
.
Add
(
key
,
value
);
this
.
UnLock
(
key
);
}
this
.
locations
[
key
]
=
value
;
private
void
UnLock
(
long
key
)
{
this
.
lockDict
.
Remove
(
key
);
if
(!
this
.
taskQueues
.
TryGetValue
(
key
,
out
Queue
<
LocationTask
>
tasks
))
{
...
...
@@ -136,7 +168,7 @@ namespace Model
this
.
taskQueues
.
Remove
(
key
);
return
;
}
if
(
this
.
lock
Set
.
Contains
(
key
))
if
(
this
.
lock
Dict
.
ContainsKey
(
key
))
{
return
;
}
...
...
@@ -146,22 +178,22 @@ namespace Model
}
}
public
Task
<
bool
>
LockAsync
(
long
key
)
public
Task
<
bool
>
LockAsync
(
long
key
,
int
time
)
{
if
(!
this
.
lock
Set
.
Contains
(
key
))
if
(!
this
.
lock
Dict
.
ContainsKey
(
key
))
{
this
.
Lock
(
key
);
this
.
Lock
(
key
,
time
);
return
Task
.
FromResult
(
true
);
}
LocationLockTask
task
=
new
LocationLockTask
(
key
);
LocationLockTask
task
=
new
LocationLockTask
(
key
,
time
);
this
.
AddTask
(
key
,
task
);
return
task
.
Task
;
}
public
Task
<
string
>
GetAsync
(
long
key
)
{
if
(!
this
.
lock
Set
.
Contains
(
key
))
if
(!
this
.
lock
Dict
.
ContainsKey
(
key
))
{
this
.
locations
.
TryGetValue
(
key
,
out
string
location
);
return
Task
.
FromResult
(
location
);
...
...
Server/Model/Component/LocationProxyComponent.cs
浏览文件 @
69d0ef37
...
...
@@ -15,9 +15,13 @@ namespace Model
{
public
string
LocationAddress
;
public
int
AppId
;
public
void
Awake
()
{
this
.
LocationAddress
=
Game
.
Scene
.
GetComponent
<
StartConfigComponent
>().
LocationConfig
.
GetComponent
<
InnerConfig
>().
Address
;
StartConfig
startConfig
=
Game
.
Scene
.
GetComponent
<
StartConfigComponent
>().
LocationConfig
;
this
.
AppId
=
startConfig
.
AppId
;
this
.
LocationAddress
=
startConfig
.
GetComponent
<
InnerConfig
>().
Address
;
}
public
async
Task
Add
(
long
key
)
...
...
@@ -26,6 +30,18 @@ namespace Model
await
session
.
Call
<
ObjectAddResponse
>(
new
ObjectAddRequest
()
{
Key
=
key
});
}
public
async
Task
Lock
(
long
key
,
int
time
=
1000
)
{
Session
session
=
Game
.
Scene
.
GetComponent
<
NetInnerComponent
>().
Get
(
this
.
LocationAddress
);
await
session
.
Call
<
ObjectLockResponse
>(
new
ObjectLockRequest
()
{
Key
=
key
,
AppId
=
this
.
AppId
,
Time
=
time
});
}
public
async
Task
UnLock
(
long
key
,
string
value
)
{
Session
session
=
Game
.
Scene
.
GetComponent
<
NetInnerComponent
>().
Get
(
this
.
LocationAddress
);
await
session
.
Call
<
ObjectUnLockResponse
>(
new
ObjectUnLockRequest
()
{
Key
=
key
,
AppId
=
this
.
AppId
,
Value
=
value
});
}
public
async
Task
Remove
(
long
key
)
{
Session
session
=
Game
.
Scene
.
GetComponent
<
NetInnerComponent
>().
Get
(
this
.
LocationAddress
);
...
...
Server/Model/Entity/DBEntity.cs
浏览文件 @
69d0ef37
...
...
@@ -5,6 +5,7 @@ namespace Model
[
BsonIgnoreExtraElements
]
[
BsonKnownTypes
(
typeof
(
RechargeRecord
))]
[
BsonKnownTypes
(
typeof
(
Recharge
))]
[
BsonKnownTypes
(
typeof
(
Location
))]
public
class
DBEntity
:
Entity
{
protected
DBEntity
()
...
...
Server/Model/Entity/Location.cs
0 → 100644
浏览文件 @
69d0ef37
namespace
Model
{
public
class
Location
:
DBEntity
{
public
string
Address
;
public
Location
(
long
id
,
string
address
):
base
(
id
)
{
this
.
Address
=
address
;
}
}
}
Server/Model/Entity/Message/InnerMessage.cs
浏览文件 @
69d0ef37
...
...
@@ -56,11 +56,11 @@ namespace Model { [Message(Opcode.R2G_GetLoginKey)] [BsonIgnoreExtraElements]
[
Message
(
Opcode
.
ObjectRemoveResponse
)]
[
BsonIgnoreExtraElements
]
public
class
ObjectRemoveResponse
:
AResponse
{
}
[
Message
(
Opcode
.
ObjectLockRequest
)]
[
BsonIgnoreExtraElements
]
public
class
ObjectLockRequest
:
ARequest
{
public
long
Key
{
get
;
set
;
}
}
[
Message
(
Opcode
.
ObjectLockRequest
)]
[
BsonIgnoreExtraElements
]
public
class
ObjectLockRequest
:
ARequest
{
public
long
Key
{
get
;
set
;
}
public
int
AppId
{
get
;
set
;
}
public
int
Time
{
get
;
set
;
}
}
[
Message
(
Opcode
.
ObjectLockResponse
)]
[
BsonIgnoreExtraElements
]
public
class
ObjectLockResponse
:
AResponse
{
}
[
Message
(
Opcode
.
ObjectUnLockRequest
)]
[
BsonIgnoreExtraElements
]
public
class
ObjectUnLockRequest
:
ARequest
{
public
long
Key
{
get
;
set
;
}
public
string
Value
{
get
;
set
;
}
}
[
Message
(
Opcode
.
ObjectUnLockRequest
)]
[
BsonIgnoreExtraElements
]
public
class
ObjectUnLockRequest
:
ARequest
{
public
long
Key
{
get
;
set
;
}
public
int
AppId
{
get
;
set
;
}
public
string
Value
{
get
;
set
;
}
}
[
Message
(
Opcode
.
ObjectUnLockResponse
)]
[
BsonIgnoreExtraElements
]
public
class
ObjectUnLockResponse
:
AResponse
{
}
...
...
Server/Model/Message/AMActorHandler.cs
浏览文件 @
69d0ef37
using
System
;
using
System.Threading.Tasks
;
namespace
Model
{
public
abstract
class
AMActorHandler
<
E
,
Message
>:
IMActorHandler
where
E
:
Entity
where
Message
:
AActorMessage
{
protected
abstract
void
Run
(
E
entity
,
Message
message
);
protected
abstract
Task
<
bool
>
Run
(
E
entity
,
Message
message
);
public
void
Handle
(
Session
session
,
Entity
entity
,
object
msg
)
public
async
Task
<
bool
>
Handle
(
Session
session
,
Entity
entity
,
object
msg
)
{
Message
message
=
msg
as
Message
;
if
(
message
==
null
)
{
Log
.
Error
(
$"消息类型转换错误:
{
msg
.
GetType
().
FullName
}
to
{
typeof
(
Message
).
Name
}
"
);
return
;
return
false
;
}
E
e
=
entity
as
E
;
if
(
e
==
null
)
{
Log
.
Error
(
$"Actor类型转换错误:
{
entity
.
GetType
().
Name
}
to
{
typeof
(
E
).
Name
}
"
);
return
;
return
false
;
}
this
.
Run
(
e
,
message
);
return
await
this
.
Run
(
e
,
message
);
}
public
Type
GetMessageType
()
...
...
@@ -39,9 +40,9 @@ namespace Model
reply
(
response
);
}
protected
abstract
void
Run
(
E
entity
,
Request
message
,
Action
<
Response
>
reply
);
protected
abstract
Task
<
bool
>
Run
(
E
entity
,
Request
message
,
Action
<
Response
>
reply
);
public
void
Handle
(
Session
session
,
Entity
entity
,
object
message
)
public
async
Task
<
bool
>
Handle
(
Session
session
,
Entity
entity
,
object
message
)
{
try
{
...
...
@@ -49,15 +50,15 @@ namespace Model
if
(
request
==
null
)
{
Log
.
Error
(
$"消息类型转换错误:
{
message
.
GetType
().
FullName
}
to
{
typeof
(
Request
).
Name
}
"
);
return
;
return
false
;
}
E
e
=
entity
as
E
;
if
(
e
==
null
)
{
Log
.
Error
(
$"Actor类型转换错误:
{
entity
.
GetType
().
Name
}
to
{
typeof
(
E
).
Name
}
"
);
return
;
return
false
;
}
this
.
Run
(
e
,
request
,
response
=>
return
await
this
.
Run
(
e
,
request
,
response
=>
{
// 等回调回来,session可以已经断开了,所以需要判断session id是否为0
if
(
session
.
Id
==
0
)
...
...
Server/Model/Message/IEntityActorHandler.cs
浏览文件 @
69d0ef37
using
System.Threading.Tasks
;
namespace
Model
{
public
interface
IEntityActorHandler
{
void
Handle
(
Session
session
,
Entity
entity
,
IActorMessage
message
);
Task
<
bool
>
Handle
(
Session
session
,
Entity
entity
,
IActorMessage
message
);
}
/// <summary>
...
...
@@ -10,18 +12,19 @@ namespace Model
/// </summary>
public
class
GateSessionEntityActorHandler
:
IEntityActorHandler
{
public
void
Handle
(
Session
session
,
Entity
entity
,
IActorMessage
message
)
public
async
Task
<
bool
>
Handle
(
Session
session
,
Entity
entity
,
IActorMessage
message
)
{
message
.
Id
=
0
;
((
Session
)
entity
).
Send
((
AMessage
)
message
);
return
true
;
}
}
public
class
CommonEntityActorHandler
:
IEntityActorHandler
{
public
void
Handle
(
Session
session
,
Entity
entity
,
IActorMessage
message
)
public
async
Task
<
bool
>
Handle
(
Session
session
,
Entity
entity
,
IActorMessage
message
)
{
Game
.
Scene
.
GetComponent
<
ActorMessageDispatherComponent
>().
Handle
(
session
,
entity
,
message
);
return
await
Game
.
Scene
.
GetComponent
<
ActorMessageDispatherComponent
>().
Handle
(
session
,
entity
,
message
);
}
}
}
\ No newline at end of file
Server/Model/Message/IMActorHandler.cs
浏览文件 @
69d0ef37
using
System
;
using
System.Threading.Tasks
;
namespace
Model
{
public
interface
IMActorHandler
{
void
Handle
(
Session
session
,
Entity
entity
,
object
message
);
Task
<
bool
>
Handle
(
Session
session
,
Entity
entity
,
object
message
);
Type
GetMessageType
();
}
}
\ No newline at end of file
Server/Model/Server.Model.csproj
浏览文件 @
69d0ef37
...
...
@@ -70,6 +70,7 @@
<Compile
Include=
"Component\ActorProxyComponent.cs"
/>
<Compile
Include=
"Component\GamerComponent.cs"
/>
<Compile
Include=
"Entity\Gamer.cs"
/>
<Compile
Include=
"Entity\Location.cs"
/>
<Compile
Include=
"Message\IEntityActorHandler.cs"
/>
<Compile
Include=
"Component\OpcodeTypeComponent.cs"
/>
<Compile
Include=
"Component\ActorManagerComponent.cs"
/>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录