forked from leeveel/GeekServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
62 additions
and
6 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
| ||
using NLog; | ||
|
||
namespace Geek.Server | ||
{ | ||
public static class EventDispatcher | ||
{ | ||
public static void Dispatch(long id, int evtId, Param args = null) | ||
{ | ||
var actor = ActorMgr.GetActor(id); | ||
if (actor != null) | ||
{ | ||
var evt = new Event | ||
{ | ||
EventId = evtId, | ||
Data = args | ||
}; | ||
|
||
actor.Tell(async () => | ||
{ | ||
// 事件需要在本actor内执行,不可多线程执行,所以不能使用Task.WhenAll来处理 | ||
var listeners = HotfixMgr.FindListeners(actor.Type, evtId); | ||
if (listeners.IsNullOrEmpty()) | ||
{ | ||
// Log.Warn($"事件:{(EventID)evtId} 没有找到任何监听者"); | ||
return; | ||
} | ||
foreach (var listener in listeners) | ||
{ | ||
var comp = await actor.GetCompAgent(listener.AgentType); | ||
await listener.HandleEvent(comp, evt); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters