diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game-server/character.cpp | 6 | ||||
-rw-r--r-- | src/game-server/character.h | 6 | ||||
-rw-r--r-- | src/game-server/gamehandler.cpp | 2 | ||||
-rw-r--r-- | src/scripting/lua.cpp | 8 |
4 files changed, 22 insertions, 0 deletions
diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index bf7c1909..b0993afa 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -55,6 +55,7 @@ const float Character::EXP_LEVEL_FLEXIBILITY = 1.0f; Script::Ref Character::mDeathCallback; Script::Ref Character::mDeathAcceptedCallback; +Script::Ref Character::mLoginCallback; static bool executeCallback(Script::Ref function, Character *character) { @@ -822,3 +823,8 @@ void Character::clearSpecials() { mSpecials.clear(); } + +void Character::triggerLoginCallback() +{ + executeCallback(mLoginCallback, this); +} diff --git a/src/game-server/character.h b/src/game-server/character.h index 48c18324..4dc077e8 100644 --- a/src/game-server/character.h +++ b/src/game-server/character.h @@ -419,6 +419,11 @@ class Character : public Being static void setDeathAcceptedCallback(Script *script) { script->assignCallback(mDeathAcceptedCallback); } + static void setLoginCallback(Script *script) + { script->assignCallback(mLoginCallback); } + + void triggerLoginCallback(); + virtual void addAttack(AttackInfo *attackInfo); virtual void removeAttack(AttackInfo *attackInfo); @@ -531,6 +536,7 @@ class Character : public Being static Script::Ref mDeathCallback; static Script::Ref mDeathAcceptedCallback; + static Script::Ref mLoginCallback; // Set as a friend, but still a lot of redundant accessors. FIXME. template< class T > diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp index f7ee6af4..8b8c67a3 100644 --- a/src/game-server/gamehandler.cpp +++ b/src/game-server/gamehandler.cpp @@ -371,6 +371,8 @@ void GameHandler::tokenMatched(GameClient *computer, Character *character) computer->disconnect(result); return; } + // Trigger login script bind + character->triggerLoginCallback(); result.writeInt8(ERRMSG_OK); computer->send(result); diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 1b8483db..ae9ba936 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -92,6 +92,13 @@ static int on_character_death_accept(lua_State *s) return 0; } +static int on_character_login(lua_State *s) +{ + luaL_checktype(s, 1, LUA_TFUNCTION); + Character::setLoginCallback(getScript(s)); + return 0; +} + static int on_being_death(lua_State *s) { luaL_checktype(s, 1, LUA_TFUNCTION); @@ -2480,6 +2487,7 @@ LuaScript::LuaScript(): static luaL_Reg const callbacks[] = { { "on_character_death", &on_character_death }, { "on_character_death_accept", &on_character_death_accept }, + { "on_character_login", &on_character_login }, { "on_being_death", &on_being_death }, { "on_being_remove", &on_being_remove }, { "on_update", &on_update }, |