Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -r a8a4d5213b1e -r f6c2d27eb104 master/master.cpp
- --- a/master/master.cpp Sat Jan 12 13:30:52 2013 +0100
- +++ b/master/master.cpp Sun Jan 13 11:34:27 2013 +0100
- @@ -1116,6 +1116,12 @@
- }
- + TNL_IMPLEMENT_RPC_OVERRIDE(MasterServerConnection, c2mRequestMOTD, ())
- + {
- + sendMotd();
- + }
- +
- +
- // Game server wants to know if user name has been verified
- TNL_IMPLEMENT_RPC_OVERRIDE(MasterServerConnection, s2mRequestAuthentication, (Vector<U8> id, StringTableEntry name))
- {
- diff -r a8a4d5213b1e -r f6c2d27eb104 master/master.h
- --- a/master/master.h Sat Jan 12 13:30:52 2013 +0100
- +++ b/master/master.h Sun Jan 13 11:34:27 2013 +0100
- @@ -251,6 +251,9 @@
- TNL_DECLARE_RPC_OVERRIDE(s2mSendLevelInfo, (string hash, string levelName, string creator,
- StringTableEntry gametype, bool hasLevelGen, U8 teamCount, S32 winningScore, S32 gameDurationInSeconds));
- + // Send message-of-the-day
- + TNL_DECLARE_RPC_OVERRIDE(c2mRequestMOTD, ());
- +
- // Send high scores stats to client
- TNL_DECLARE_RPC_OVERRIDE(c2mRequestHighScores, ());
- diff -r a8a4d5213b1e -r f6c2d27eb104 master/masterInterface.cpp
- --- a/master/masterInterface.cpp Sat Jan 12 13:30:52 2013 +0100
- +++ b/master/masterInterface.cpp Sun Jan 13 11:34:27 2013 +0100
- @@ -84,6 +84,11 @@
- NetClassGroupMasterMask, RPCGuaranteedOrdered, RPCDirClientToServer, 0) {}
- +TNL_IMPLEMENT_RPC(MasterServerInterface, c2mRequestMOTD,
- + (),
- + (),
- + NetClassGroupMasterMask, RPCGuaranteedOrdered, RPCDirClientToServer, 2) {}
- +
- TNL_IMPLEMENT_RPC(MasterServerInterface, m2cSetMOTD,
- (TNL::StringPtr masterName, TNL::StringPtr motdString),
- (masterName, motdString),
- diff -r a8a4d5213b1e -r f6c2d27eb104 master/masterInterface.h
- --- a/master/masterInterface.h Sat Jan 12 13:30:52 2013 +0100
- +++ b/master/masterInterface.h Sun Jan 13 11:34:27 2013 +0100
- @@ -132,9 +132,11 @@
- StringTableEntry levelName, StringTableEntry levelType,
- U32 botCount, U32 playerCount, U32 maxPlayers, U32 infoFlags));
- + /// Request the Message-of-the-Day
- + TNL_DECLARE_RPC(c2mRequestMOTD, ());
- /// m2cSetMOTD is sent to a client when the connection is established. The
- - /// client's game string is used to pick which MOTD will be sent.
- + /// client's BUILD_VERSION is used to pick which MOTD will be sent.
- TNL_DECLARE_RPC(m2cSetMOTD, (TNL::StringPtr masterName, TNL::StringPtr motdString));
- // If the user has a verified name, send this message back so they know the "correct spelling" of the name
- diff -r a8a4d5213b1e -r f6c2d27eb104 tnl/tnlNetConnection.h
- --- a/tnl/tnlNetConnection.h Sat Jan 12 13:30:52 2013 +0100
- +++ b/tnl/tnlNetConnection.h Sun Jan 13 11:34:27 2013 +0100
- @@ -244,6 +244,7 @@
- ReasonConnectionsForbidden, // Used when rejecting data connections when data connection capability is disabled
- ReasonBanned, // You made the admin mad...
- + ReasonAnonymous, // Anonymous connections are terminated quickly, only for simple data retrieval
- TerminationReasons, // Must be last of enumerated reasons!
- ReasonNone
- };
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/ClientGame.cpp
- --- a/zap/ClientGame.cpp Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/ClientGame.cpp Sun Jan 13 11:34:27 2013 +0100
- @@ -1259,8 +1259,12 @@
- mSeenTimeOutMessage = true;
- break;
- +
- case NetConnection::ReasonSelfDisconnect:
- - break; // no errors when client disconnect (when quitting bitfighter)
- + // no errors when client disconnect (when quitting bitfighter)
- + case NetConnection::ReasonAnonymous:
- + // Anonymous connections are disconnected quickly, usually after retrieving some data
- + break;
- default: // Not handled
- ui->setMessage(2, "Unable to connect to the master server, with error code:");
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/EngineeredItem.cpp
- --- a/zap/EngineeredItem.cpp Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/EngineeredItem.cpp Sun Jan 13 11:34:27 2013 +0100
- @@ -1689,10 +1689,20 @@
- // Combined Lua / C++ default constructor
- Turret::Turret(lua_State *L) : Parent(TEAM_NEUTRAL, Point(0,0), Point(1,0))
- {
- + // TODO: This does not work; we need to snap the turret to a nearby wall and compute the normal angle.
- + // It is likely that setPos is similarly broken. And maybe more.
- + if(L)
- + {
- + static LuaFunctionArgList constructorArgList = { {{ END }, { GEOM, TEAM_INDX, END }}, 2 };
- + S32 profile = checkArgList(L, constructorArgList, "Turret", "constructor");
- + findMountPoint(Game::getAddTarget(), getPos());
- + if(profile == 1)
- + {
- + findMountPoint(gServerGame, getPointOrXY(L, 1));
- + setTeam(getInt(L, 2));
- + }
- + }
- initialize();
- -
- - if(L)
- - findMountPoint(Game::getAddTarget(), getPos());
- }
- @@ -2039,6 +2049,8 @@
- /////
- // Lua interface
- /**
- + * @luafunc Turret::Turret()
- + * @luafunc Turret::Turret(geom, team)
- * @luaclass Turret
- * @brief Mounted gun that shoots at enemy ships and other objects.
- */
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/EventManager.cpp
- --- a/zap/EventManager.cpp Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/EventManager.cpp Sun Jan 13 11:34:27 2013 +0100
- @@ -44,16 +44,16 @@
- struct Subscription {
- - const char *scriptId;
- + LuaScriptRunner *subscriber;
- LuaBase::ScriptContext context;
- };
- // Statics:
- bool EventManager::anyPending = false;
- -Vector<Subscription> EventManager::subscriptions[EventTypes];
- -Vector<Subscription> EventManager::pendingSubscriptions[EventTypes];
- -Vector<const char *> EventManager::pendingUnsubscriptions[EventTypes];
- +static Vector<Subscription> subscriptions [EventManager::EventTypes];
- +static Vector<Subscription> pendingSubscriptions [EventManager::EventTypes];
- +static Vector<LuaScriptRunner *> pendingUnsubscriptions[EventManager::EventTypes];
- bool EventManager::mConstructed = false; // Prevent duplicate instantiation
- @@ -113,7 +113,7 @@
- }
- -void EventManager::subscribe(const char *subscriber, EventType eventType, LuaBase::ScriptContext context, bool failSilently)
- +void EventManager::subscribe(LuaScriptRunner *subscriber, EventType eventType, LuaBase::ScriptContext context, bool failSilently)
- {
- // First, see if we're already subscribed
- if(isSubscribed(subscriber, eventType) || isPendingSubscribed(subscriber, eventType))
- @@ -122,7 +122,7 @@
- lua_State *L = LuaScriptRunner::getL();
- // Make sure the script has the proper event listener
- - bool ok = LuaScriptRunner::loadFunction(L, subscriber, eventDefs[eventType].function); // -- function
- + bool ok = LuaScriptRunner::loadFunction(L, subscriber->getScriptId(), eventDefs[eventType].function); // -- function
- if(!ok)
- {
- @@ -137,7 +137,7 @@
- removeFromPendingUnsubscribeList(subscriber, eventType);
- Subscription s;
- - s.scriptId = subscriber;
- + s.subscriber = subscriber;
- s.context = context;
- pendingSubscriptions[eventType].push_back(s);
- @@ -147,7 +147,7 @@
- }
- -void EventManager::unsubscribe(const char *subscriber, EventType eventType)
- +void EventManager::unsubscribe(LuaScriptRunner *subscriber, EventType eventType)
- {
- if((isSubscribed(subscriber, eventType) || isPendingSubscribed(subscriber, eventType)) && !isPendingUnsubscribed(subscriber, eventType))
- {
- @@ -159,10 +159,10 @@
- }
- -void EventManager::removeFromPendingSubscribeList(const char *subscriber, EventType eventType)
- +void EventManager::removeFromPendingSubscribeList(LuaScriptRunner *subscriber, EventType eventType)
- {
- for(S32 i = 0; i < pendingSubscriptions[eventType].size(); i++)
- - if(strcmp(pendingSubscriptions[eventType][i].scriptId, subscriber) == 0)
- + if(pendingSubscriptions[eventType][i].subscriber == subscriber)
- {
- pendingSubscriptions[eventType].erase_fast(i);
- return;
- @@ -170,10 +170,10 @@
- }
- -void EventManager::removeFromPendingUnsubscribeList(const char *subscriber, EventType eventType)
- +void EventManager::removeFromPendingUnsubscribeList(LuaScriptRunner *subscriber, EventType eventType)
- {
- for(S32 i = 0; i < pendingUnsubscriptions[eventType].size(); i++)
- - if(strcmp(pendingUnsubscriptions[eventType][i], subscriber) == 0)
- + if(pendingUnsubscriptions[eventType][i] == subscriber)
- {
- pendingUnsubscriptions[eventType].erase_fast(i);
- return;
- @@ -181,10 +181,10 @@
- }
- -void EventManager::removeFromSubscribedList(const char *subscriber, EventType eventType)
- +void EventManager::removeFromSubscribedList(LuaScriptRunner *subscriber, EventType eventType)
- {
- for(S32 i = 0; i < subscriptions[eventType].size(); i++)
- - if(strcmp(subscriptions[eventType][i].scriptId, subscriber) == 0)
- + if(subscriptions[eventType][i].subscriber == subscriber)
- {
- subscriptions[eventType].erase_fast(i);
- return;
- @@ -193,39 +193,39 @@
- // Unsubscribe an event bypassing the pending unsubscribe queue, when we know it will be OK
- -void EventManager::unsubscribeImmediate(const char *subscriber, EventType eventType)
- +void EventManager::unsubscribeImmediate(LuaScriptRunner *subscriber, EventType eventType)
- {
- - removeFromSubscribedList(subscriber, eventType);
- - removeFromPendingSubscribeList(subscriber, eventType);
- + removeFromSubscribedList (subscriber, eventType);
- + removeFromPendingSubscribeList (subscriber, eventType);
- removeFromPendingUnsubscribeList(subscriber, eventType); // Probably not really necessary...
- }
- // Check if we're subscribed to an event
- -bool EventManager::isSubscribed(const char *subscriber, EventType eventType)
- +bool EventManager::isSubscribed(LuaScriptRunner *subscriber, EventType eventType)
- {
- for(S32 i = 0; i < subscriptions[eventType].size(); i++)
- - if(strcmp(subscriptions[eventType][i].scriptId, subscriber) == 0)
- + if(subscriptions[eventType][i].subscriber == subscriber)
- return true;
- return false;
- }
- -bool EventManager::isPendingSubscribed(const char *subscriber, EventType eventType)
- +bool EventManager::isPendingSubscribed(LuaScriptRunner *subscriber, EventType eventType)
- {
- for(S32 i = 0; i < pendingSubscriptions[eventType].size(); i++)
- - if(strcmp(pendingSubscriptions[eventType][i].scriptId, subscriber) == 0)
- + if(pendingSubscriptions[eventType][i].subscriber == subscriber)
- return true;
- return false;
- }
- -bool EventManager::isPendingUnsubscribed(const char *subscriber, EventType eventType)
- +bool EventManager::isPendingUnsubscribed(LuaScriptRunner *subscriber, EventType eventType)
- {
- for(S32 i = 0; i < pendingUnsubscriptions[eventType].size(); i++)
- - if(strcmp(pendingUnsubscriptions[eventType][i], subscriber) == 0)
- + if(pendingUnsubscriptions[eventType][i] == subscriber)
- return true;
- return false;
- @@ -265,23 +265,7 @@
- lua_State *L = LuaScriptRunner::getL();
- for(S32 i = 0; i < subscriptions[eventType].size(); i++)
- - {
- - try
- - {
- - // Passing nothing
- - bool error = LuaScriptRunner::loadFunction(L, subscriptions[eventType][i].scriptId, eventDefs[eventType].function);
- - if(error)
- - throw LuaException("Could not load function!");
- -
- - fire(L, 0, subscriptions[eventType][i].context);
- - }
- - catch(LuaException &e)
- - {
- - handleEventFiringError(L, subscriptions[eventType][i], eventType, e.what());
- - LuaObject::clearStack(L);
- - return;
- - }
- - }
- + fire(L, subscriptions[eventType][i].subscriber, eventDefs[eventType].function, subscriptions[eventType][i].context);
- }
- @@ -298,20 +282,8 @@
- for(S32 i = 0; i < subscriptions[eventType].size(); i++)
- {
- - try
- - {
- - // Passing time
- - LuaScriptRunner::loadFunction(L, subscriptions[eventType][i].scriptId, eventDefs[eventType].function);
- - lua_pushinteger(L, deltaT);
- -
- - fire(L, 1, subscriptions[eventType][i].context);
- - }
- - catch(LuaException &e)
- - {
- - handleEventFiringError(L, subscriptions[eventType][i], eventType, e.what());
- - LuaObject::clearStack(L);
- - return;
- - }
- + lua_pushinteger(L, deltaT); // -- deltaT
- + fire(L, subscriptions[eventType][i].subscriber, eventDefs[eventType].function, subscriptions[eventType][i].context);
- }
- }
- @@ -326,27 +298,15 @@
- for(S32 i = 0; i < subscriptions[eventType].size(); i++)
- {
- - try
- - {
- - // Passing ship
- - LuaScriptRunner::loadFunction(L, subscriptions[eventType][i].scriptId, eventDefs[eventType].function);
- - ship->push(L);
- -
- - fire(L, 1, subscriptions[eventType][i].context);
- - }
- - catch(LuaException &e)
- - {
- - handleEventFiringError(L, subscriptions[eventType][i], eventType, e.what());
- - LuaObject::clearStack(L);
- - return;
- - }
- + ship->push(L); // -- ship
- + fire(L, subscriptions[eventType][i].subscriber, eventDefs[eventType].function, subscriptions[eventType][i].context);
- }
- }
- // Note that player can be NULL, in which case we'll pass nil to the listeners
- // callerId will be NULL when player sends message
- -void EventManager::fireEvent(const char *callerId, EventType eventType, const char *message, LuaPlayerInfo *player, bool global)
- +void EventManager::fireEvent(LuaScriptRunner *sender, EventType eventType, const char *message, LuaPlayerInfo *playerInfo, bool global)
- {
- if(suppressEvents(eventType))
- return;
- @@ -355,36 +315,25 @@
- for(S32 i = 0; i < subscriptions[eventType].size(); i++)
- {
- - if(callerId && strcmp(callerId, subscriptions[eventType][i].scriptId) == 0) // Don't alert bot about own message!
- + if(sender == subscriptions[eventType][i].subscriber) // Don't alert sender about own message!
- continue;
- - try
- - {
- - // Passing msg, player, isGlobal
- - LuaScriptRunner::loadFunction(L, subscriptions[eventType][i].scriptId, eventDefs[eventType].function);
- - lua_pushstring(L, message);
- + lua_pushstring(L, message); // -- message
- - if(player)
- - player->push(L);
- - else
- - lua_pushnil(L);
- + if(playerInfo)
- + playerInfo->push(L); // -- message, playerInfo
- + else
- + lua_pushnil(L);
- - lua_pushboolean(L, global);
- + lua_pushboolean(L, global); // -- message, player, isGlobal
- - fire(L, 3, subscriptions[eventType][i].context);
- - }
- - catch(LuaException &e)
- - {
- - handleEventFiringError(L, subscriptions[eventType][i], eventType, e.what());
- - LuaObject::clearStack(L);
- - return;
- - }
- + fire(L, subscriptions[eventType][i].subscriber, eventDefs[eventType].function, subscriptions[eventType][i].context);
- }
- }
- // onPlayerJoined, onPlayerLeft
- -void EventManager::fireEvent(const char *callerId, EventType eventType, LuaPlayerInfo *player)
- +void EventManager::fireEvent(LuaScriptRunner *player, EventType eventType, LuaPlayerInfo *playerInfo)
- {
- if(suppressEvents(eventType))
- return;
- @@ -393,23 +342,11 @@
- for(S32 i = 0; i < subscriptions[eventType].size(); i++)
- {
- - if(strcmp(callerId, subscriptions[eventType][i].scriptId) == 0) // Don't trouble bot with own joinage or leavage!
- + if(player == subscriptions[eventType][i].subscriber) // Don't trouble player with own joinage or leavage!
- continue;
- - try
- - {
- - // Passing player
- - LuaScriptRunner::loadFunction(L, subscriptions[eventType][i].scriptId, eventDefs[eventType].function);
- - player->push(L);
- -
- - fire(L, 1, subscriptions[eventType][i].context);
- - }
- - catch(LuaException &e)
- - {
- - handleEventFiringError(L, subscriptions[eventType][i], eventType, e.what());
- - LuaObject::clearStack(L);
- - return;
- - }
- + playerInfo->push(L); // -- playerInfo
- + fire(L, subscriptions[eventType][i].subscriber, eventDefs[eventType].function, subscriptions[eventType][i].context);
- }
- }
- @@ -427,13 +364,12 @@
- try
- {
- // Passing ship, zone, zoneType, zoneId
- - LuaScriptRunner::loadFunction(L, subscriptions[eventType][i].scriptId, eventDefs[eventType].function);
- - ship->push(L);
- - zone->push(L);
- - lua_pushinteger(L, zone->getObjectTypeNumber());
- - lua_pushinteger(L, zone->getUserAssignedId());
- + ship->push(L); // -- ship
- + zone->push(L); // -- ship, zone
- + lua_pushinteger(L, zone->getObjectTypeNumber()); // -- ship, zone, zone->objTypeNumber
- + lua_pushinteger(L, zone->getUserAssignedId()); // -- ship, zone, zone->objTypeNumber, zone->id
- - fire(L, 4, subscriptions[eventType][i].context);
- + fire(L, subscriptions[eventType][i].subscriber, eventDefs[eventType].function, subscriptions[eventType][i].context);
- }
- catch(LuaException &e)
- {
- @@ -445,12 +381,12 @@
- }
- -// Actually fire the event, called by one fo the fireEvent() methods above
- -void EventManager::fire(lua_State *L, S32 argCount, LuaBase::ScriptContext context)
- +// Actually fire the event, called by one of the fireEvent() methods above
- +// Returns true if there was an error, false if everything ran ok
- +bool EventManager::fire(lua_State *L, LuaScriptRunner *scriptRunner, const char *function, LuaBase::ScriptContext context)
- {
- LuaBase::setScriptContext(L, context);
- - if(lua_pcall(L, argCount, 0, 0) != 0)
- - throw LuaException(lua_tostring(L, -1));
- + return scriptRunner->runCmd(function, 0);
- }
- @@ -458,16 +394,8 @@
- {
- if(subscriber.context == LuaBase::RobotContext)
- {
- - // Figure out which, if any, bot caused the error
- - Robot *robot = gServerGame->findBot(subscriber.scriptId);
- -
- - TNLAssert(robot, "Could not find robot!");
- -
- - if(robot)
- - {
- - robot->logError("Error handling event %s: %s. Shutting bot down.", eventDefs[eventType].name, errorMsg);
- - delete robot;
- - }
- + subscriber.subscriber->logError("Error handling event %s: %s. Shutting bot down.", eventDefs[eventType].name, errorMsg);
- + delete subscriber.subscriber;
- }
- else
- {
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/EventManager.h
- --- a/zap/EventManager.h Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/EventManager.h Sun Jan 13 11:34:27 2013 +0100
- @@ -29,7 +29,6 @@
- #include "tnlTypes.h"
- #include "tnlVector.h"
- #include "LuaBase.h" // For ScriptContext def
- -//#include "lua.h"
- using namespace TNL;
- @@ -39,6 +38,7 @@
- class Robot;
- class Ship;
- class LuaPlayerInfo;
- +class LuaScriptRunner;
- class Zone;
- struct Subscription;
- @@ -77,16 +77,16 @@
- private:
- // Some helper functions
- - bool isSubscribed(const char *subscriber, EventType eventType);
- - bool isPendingSubscribed(const char *subscriber, EventType eventType);
- - bool isPendingUnsubscribed(const char *subscriber, EventType eventType);
- + bool isSubscribed (LuaScriptRunner *subscriber, EventType eventType);
- + bool isPendingSubscribed (LuaScriptRunner *subscriber, EventType eventType);
- + bool isPendingUnsubscribed(LuaScriptRunner *subscriber, EventType eventType);
- - void removeFromSubscribedList(const char *subscriber, EventType eventType);
- - void removeFromPendingSubscribeList(const char *subscriber, EventType eventType);
- - void removeFromPendingUnsubscribeList(const char *subscriber, EventType eventType);
- + void removeFromSubscribedList (LuaScriptRunner *subscriber, EventType eventType);
- + void removeFromPendingSubscribeList (LuaScriptRunner *subscriber, EventType eventType);
- + void removeFromPendingUnsubscribeList(LuaScriptRunner *subscriber, EventType eventType);
- void handleEventFiringError(lua_State *L, const Subscription &subscriber, EventType eventType, const char *errorMsg);
- - void fire(lua_State *L, S32 argCount, LuaBase::ScriptContext context);
- + bool fire(lua_State *L, LuaScriptRunner *scriptRunner, const char *function, LuaBase::ScriptContext context);
- bool mIsPaused;
- S32 mStepCount; // If running for a certain number of steps, this will be > 0, while mIsPaused will be true
- @@ -101,23 +101,25 @@
- static EventManager *get(); // Provide access to the single EventManager instance
- bool suppressEvents(EventType eventType);
- - static Vector<Subscription> subscriptions[EventTypes];
- - static Vector<Subscription> pendingSubscriptions[EventTypes];
- - static Vector<const char *> pendingUnsubscriptions[EventTypes];
- + //static Vector<Subscription> subscriptions[EventTypes];
- + //static Vector<Subscription> pendingSubscriptions[EventTypes];
- + //static Vector<pendingUnsubscriptions *> pendingUnsubscriptions[EventTypes];
- static bool anyPending;
- - void subscribe(const char *subscriber, EventType eventType, LuaBase::ScriptContext context, bool failSilently = false);
- - void unsubscribe(const char *subscriber, EventType eventType);
- - void unsubscribeImmediate(const char *, EventType eventType); // Used when bot dies, and we know there won't be subscription conflicts
- - void update(); // Act on events sitting in the pending lists
- + void subscribe (LuaScriptRunner *subscriber, EventType eventType, LuaBase::ScriptContext context, bool failSilently = false);
- + void unsubscribe(LuaScriptRunner *subscriber, EventType eventType);
- +
- + // Used when bot dies, and we know there won't be subscription conflicts
- + void unsubscribeImmediate(LuaScriptRunner *subscriber, EventType eventType);
- + void update(); // Act on events sitting in the pending lists
- // We'll have several different signatures for this one...
- void fireEvent(EventType eventType);
- void fireEvent(EventType eventType, U32 deltaT); // Tick
- void fireEvent(EventType eventType, Ship *ship); // ShipSpawned, ShipKilled
- - void fireEvent(const char *callerId, EventType eventType, const char *message, LuaPlayerInfo *player, bool global); // MsgReceived
- - void fireEvent(const char *callerId, EventType eventType, LuaPlayerInfo *player); // PlayerJoined, PlayerLeft
- - void fireEvent(EventType eventType, Ship *ship, Zone *zone); // ShipEnteredZoneEvent, ShipLeftZoneEvent
- + void fireEvent(LuaScriptRunner *sender, EventType eventType, const char *message, LuaPlayerInfo *playerInfo, bool global); // MsgReceived
- + void fireEvent(LuaScriptRunner *player, EventType eventType, LuaPlayerInfo *playerInfo); // PlayerJoined, PlayerLeft
- + void fireEvent(EventType eventType, Ship *ship, Zone *zone); // ShipEnteredZoneEvent, ShipLeftZoneEvent
- // Allow the pausing of event firing for debugging purposes
- void setPaused(bool isPaused);
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/LuaBase.cpp
- --- a/zap/LuaBase.cpp Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/LuaBase.cpp Sun Jan 13 11:34:27 2013 +0100
- @@ -103,7 +103,7 @@
- for(S32 i = 0; i < profileCount; i++)
- {
- - const LuaBase::LuaArgType *candidateArgList = functionArgList.argList[i];
- + const LuaBase::LuaArgType *candidateArgList = functionArgList.argList[i]; // argList is a 2D array
- bool validProfile = true;
- S32 stackPos = 0;
- @@ -262,7 +262,14 @@
- case TEAM_INDX:
- if(lua_isnumber(L, stackPos))
- {
- - lua_Integer i = lua_tointeger(L, stackPos) - 1; // -1 because Lua indices start with 1
- + lua_Integer i = lua_tointeger(L, stackPos);
- + // Special check for common error because Lua 1-based arrays suck monkey balls
- + if(i == 0)
- + logprintf(LogConsumer::LogError, "WARNING: It appears you have tried to add an item to teamIndex 0; "
- + "this is almost certainly an error.\n"
- + "If you want to add an item to the first team, specify team 1. Remember "
- + "that Lua uses 1-based arrays.");
- + i--; // Subtract 1 because Lua indices start with 1, and we need to convert to C++ 0-based index
- return ((i >= 0 && i < Game::getAddTarget()->getTeamCount()) || (i + 1) == TEAM_NEUTRAL || (i + 1) == TEAM_HOSTILE);
- }
- return false;
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/LuaScriptRunner.cpp
- --- a/zap/LuaScriptRunner.cpp Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/LuaScriptRunner.cpp Sun Jan 13 11:34:27 2013 +0100
- @@ -91,13 +91,14 @@
- // send an event to a dead bot, after all...
- for(S32 i = 0; i < EventManager::EventTypes; i++)
- if(mSubscriptions[i])
- - EventManager::get()->unsubscribeImmediate(getScriptId(), (EventManager::EventType)i);
- + EventManager::get()->unsubscribeImmediate(this, (EventManager::EventType)i);
- // And delete the script's environment table from the Lua instance
- deleteScript(getScriptId());
- }
- - const char *LuaScriptRunner::getErrorMessagePrefix() { return "SCRIPT"; }
- +
- +const char *LuaScriptRunner::getErrorMessagePrefix() { return "SCRIPT"; }
- // Static method setting static vars
- @@ -143,6 +144,7 @@
- // Retrieve the environment from the registry, and put the requested function from that environment onto the stack. Returns true
- // if it works, false if the specified function could not be found. If this fails, it will remove the non-function from the stack.
- +// Remember that not every failure to load a function is a problem; some functions are expected but optional.
- bool LuaScriptRunner::loadFunction(lua_State *L, const char *scriptId, const char *functionName)
- {
- lua_getfield(L, LUA_REGISTRYINDEX, scriptId); // Push REGISTRY[scriptId] onto the stack -- table
- @@ -151,7 +153,7 @@
- // Check if the top stack item is indeed a function (as we would expect)
- if(lua_isfunction(L, -1))
- - return true; // If so, return true
- + return true; // If so, return true, leaving the function on top of the stack
- // else
- clearStack(L);
- @@ -159,22 +161,6 @@
- }
- -bool LuaScriptRunner::retrieveCriticalFunction(const char *functionName)
- -{
- - if(!loadFunction(L, getScriptId(), functionName))
- - {
- - TNLAssert(false, "Critical function not found -- is the lua environment corrupt?");
- -
- - logError("Function %s() could not be found! Terminating script.\n"
- - "Your scripting environment appears corrupted. Consider reinstalling Bitfighter.", functionName);
- -
- - return false;
- - }
- -
- - return true;
- -}
- -
- -
- // Primarily used for loading helper functions
- bool LuaScriptRunner::loadAndRunGlobalFunction(lua_State *L, const char *key, ScriptContext context)
- {
- @@ -184,7 +170,6 @@
- setEnvironment(); // Set the environment for the code
- S32 err = lua_pcall(L, 0, 0, 0); // Run it -- <<empty stack>>
- -
- if(err != 0)
- {
- logError("Failed to load startup functions %s: %s", key, lua_tostring(L, -1));
- @@ -300,43 +285,41 @@
- // Returns true if there was an error, false if everything ran ok
- bool LuaScriptRunner::runCmd(const char *function, S32 returnValues)
- {
- - S32 args = lua_gettop(L); // Number of args on stack -- <<args>>
- + try
- + {
- + S32 args = lua_gettop(L); // Number of args on stack -- <<args>>
- - // Load our error handling function -- this will print a pretty stacktrace in the event things go wrong calling function.
- - retrieveCriticalFunction("_stackTracer"); // -- <<args>>, _stackTracer
- - bool ok = loadFunction(L, getScriptId(), function); // -- <<args>>, _stackTracer, function
- - if(!ok)
- - {
- - logprintf(LogConsumer::LogError, "%s\n"
- - "Cannot load method %s()!\n"
- - "Terminating script.",
- - getErrorMessagePrefix(), function, lua_tostring(L, -1));
- + // Load our error handling function -- this will print a pretty stacktrace in the event things go wrong calling function.
- + // _stackTracer is a function included in lua_helper_functions that manages the stack trace; it should ALWAYS be present.
- + if(!loadFunction(L, getScriptId(), "_stackTracer")) // -- <<args>>, _stackTracer
- + throw LuaException("Method _stackTracer() could not be found!\n"
- + "Your scripting environment appears corrupted. Consider reinstalling Bitfighter.");
- +
- + if(!loadFunction(L, getScriptId(), function)) // -- <<args>>, _stackTracer, function
- + throw LuaException("Cannot load method" + string(function) +"()!\n");
- +
- + // Reorder the stack a little
- + lua_insert(L, 1); // -- function, <<args>>, _stackTracer
- + lua_insert(L, 1); // -- _stackTracer, function, <<args>>
- +
- + S32 error = lua_pcall(L, args, returnValues, -2 - args); // -- _stackTracer, <<return values>>
- + if(error)
- + throw LuaException("In method" + string(function) +"():\n" + string(lua_tostring(L, -1)));
- +
- + lua_remove(L, 1); // Remove _stackTracer -- <<return values>>
- +
- + // Do not clear stack -- caller probably wants <<return values>>
- + return false;
- + }
- +
- + catch(LuaException &e)
- + {
- + logprintf(LogConsumer::LogError, "%s\n%s\nTerminating script", getErrorMessagePrefix(), e.msg.c_str());
- +
- killScript();
- clearStack(L);
- return true;
- }
- -
- - // Reorder the stack a little
- - lua_insert(L, 1); // -- function, <<args>>, _stackTracer
- - lua_insert(L, 1); // -- _stackTracer, function, <<args>>
- -
- - S32 error = lua_pcall(L, args, returnValues, -2 - args); // -- _stackTracer, <<return values>>
- -
- - if(error != 0)
- - {
- - logprintf(LogConsumer::LogError, "%s\n"
- - "In method %s():\n"
- - "%s.\n",
- - getErrorMessagePrefix(), function, lua_tostring(L, -1)); // Gets stack trace left by _stackTracer
- - killScript();
- - clearStack(L);
- - return true;
- - }
- -
- - lua_remove(L, 1); // Remove _stackTracer -- <<return values>>
- -
- - // Do not clear stack -- caller probably wants <<return values>>
- - return false;
- }
- @@ -611,7 +594,7 @@
- if(!mSubscriptions[eventType])
- {
- - EventManager::get()->subscribe(getScriptId(), (EventManager::EventType)eventType, context);
- + EventManager::get()->subscribe(this, (EventManager::EventType)eventType, context);
- mSubscriptions[eventType] = true;
- }
- @@ -627,7 +610,7 @@
- if(mSubscriptions[eventType])
- {
- - EventManager::get()->unsubscribe(getScriptId(), (EventManager::EventType)eventType);
- + EventManager::get()->unsubscribe(this, (EventManager::EventType)eventType);
- mSubscriptions[eventType] = false;
- }
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/LuaScriptRunner.h
- --- a/zap/LuaScriptRunner.h Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/LuaScriptRunner.h Sun Jan 13 11:34:27 2013 +0100
- @@ -165,11 +165,8 @@
- bool loadScript();
- - bool retrieveCriticalFunction(const char *funName); // Same, but with more oomph
- -
- bool runCmd(const char *function, S32 returnValues);
- -
- const char *getScriptId();
- static bool loadFunction(lua_State *L, const char *scriptId, const char *functionName);
- bool loadAndRunGlobalFunction(lua_State *L, const char *key, ScriptContext context);
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/Spawn.cpp
- --- a/zap/Spawn.cpp Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/Spawn.cpp Sun Jan 13 11:34:27 2013 +0100
- @@ -206,7 +206,16 @@
- // Lua constructor
- Spawn::Spawn(lua_State *L) : AbstractSpawn(Point(0,0))
- {
- + static LuaFunctionArgList constructorArgList = { {{ END }, { GEOM, END }, { GEOM, TEAM_INDX, END }}, 3 };
- + S32 profile = checkArgList(L, constructorArgList, "Spawn", "constructor");
- initialize();
- + if(L && profile == 1)
- + setPos(getPointOrXY(L, 1));
- + else if(L && profile == 2)
- + {
- + setPos(getPointOrXY(L, 1));
- + setTeam(getInt(L, 2));
- + }
- }
- @@ -289,6 +298,9 @@
- /////
- // Lua interface
- /**
- + * @luafunc Spawn::Spawn()
- + * @luafunc Spawn::Spawn(geom)
- + * @luafunc Spawn::Spawn(geom, team)
- * @luaclass Spawn
- * @brief Marks locations where ships and robots should spawn.
- * @geom The geometry of Spawns is a single point.
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/UIGame.cpp
- --- a/zap/UIGame.cpp Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/UIGame.cpp Sun Jan 13 11:34:27 2013 +0100
- @@ -106,7 +106,7 @@
- mChatMessageDisplayer1(game, 5, true, false, CHAT_WRAP_WIDTH, CHAT_FONT_SIZE, CHAT_FONT_GAP),
- mChatMessageDisplayer2(game, 5, false, false, CHAT_WRAP_WIDTH, CHAT_FONT_SIZE, CHAT_FONT_GAP),
- mChatMessageDisplayer3(game, 24, false, false, CHAT_WRAP_WIDTH, CHAT_FONT_SIZE, CHAT_FONT_GAP),
- - mAnnouncementTimer(0)
- + mAnnouncementTimer(0)
- {
- mInScoreboardMode = false;
- mFPSVisible = false;
- @@ -2002,7 +2002,6 @@
- for(S32 i = 1; i < words.size(); i++)
- s = s + words[i];
- - ClientInfo* clientInfo = game->getClientInfo();
- GameType* gt = game->getGameType();
- if(gt)
- @@ -2311,7 +2310,7 @@
- { "addbots", &GameUserInterface::addBotsHandler, { xINT, STR, TEAM, STR }, 4, LEVEL_COMMANDS, 1, 2, {"[count]","[file]","[team name or num]","[args]"}, "Add [count] bots from [file] to [team num], pass [args] to bot" },
- { "kickbot", &GameUserInterface::kickBotHandler, { }, 0, LEVEL_COMMANDS, 1, 1, { }, "Kick most recently added bot" },
- { "kickbots", &GameUserInterface::kickBotsHandler, { }, 0, LEVEL_COMMANDS, 1, 1, { }, "Kick all bots" },
- - {"announce", &GameUserInterface::announceHandler, { STR }, 1, ADMIN_COMMANDS, 0, 1, {"<ANNOUNCEMENT>"}, "The admin announces an important message" },
- + {"announce", &GameUserInterface::announceHandler, { STR }, 1, ADMIN_COMMANDS, 0, 1, {"<ANNOUNCEMENT>"}, "The admin announces an important message" },
- { "kick", &GameUserInterface::kickPlayerHandler, { NAME }, 1, ADMIN_COMMANDS, 0, 1, {"<name>"}, "Kick a player from the game" },
- { "ban", &GameUserInterface::banPlayerHandler, { NAME, xINT }, 2, ADMIN_COMMANDS, 0, 1, {"<name>","[duration]"}, "Ban a player from the server (IP-based, def. = 60 mins)" },
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/UIGame.h
- --- a/zap/UIGame.h Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/UIGame.h Sun Jan 13 11:34:27 2013 +0100
- @@ -150,7 +150,6 @@
- MessageDisplayModes
- };
- - Timer mAnnouncementTimer;
- string mAnnouncement;
- bool mIsAnnouncementNew;
- @@ -274,6 +273,8 @@
- ChatMessageDisplayer mChatMessageDisplayer2; // Short form, messages do not expire
- ChatMessageDisplayer mChatMessageDisplayer3; // Long form, messages do not expire
- + Timer mAnnouncementTimer;
- +
- void dropItem(); // User presses drop item key
- bool mFiring; // Are we firing?
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/Zone.cpp
- --- a/zap/Zone.cpp Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/Zone.cpp Sun Jan 13 11:34:27 2013 +0100
- @@ -26,6 +26,7 @@
- #include "Zone.h"
- #include "game.h"
- #include "stringUtils.h"
- +#include "Geometry.h"
- namespace Zap
- {
- @@ -36,6 +37,17 @@
- // Combined Lua / C++ constructor)
- Zone::Zone(lua_State *L)
- {
- + if(L)
- + {
- + static LuaFunctionArgList constructorArgList = { {{ END }, { GEOM, END }}, 2 };
- + S32 profile = checkArgList(L, constructorArgList, "Zone", "constructor");
- +
- + if(profile == 1)
- + {
- + setGeom(L, 1);
- + }
- + }
- +
- setTeam(TEAM_NEUTRAL);
- mObjectTypeNumber = ZoneTypeNumber;
- @@ -148,7 +160,9 @@
- /////
- // Lua interface
- -/**
- +/**
- + * @luafunc Zone::Zone()
- + * @luafunc Zone::Zone(geom)
- * @luaclass Zone
- * @brief Invisible objects, used mainly for generating events.
- */
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/barrier.cpp
- --- a/zap/barrier.cpp Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/barrier.cpp Sun Jan 13 11:34:27 2013 +0100
- @@ -31,6 +31,7 @@
- #include "game.h"
- #include "config.h"
- #include "stringUtils.h"
- +#include "LuaWrapper.h"
- #ifndef ZAP_DEDICATED
- # include "OpenglUtils.h"
- @@ -349,6 +350,18 @@
- mAlreadyAdded = false;
- setNewGeometry(geomPolyLine);
- +
- + if(L)
- + {
- + static LuaFunctionArgList constructorArgList = { {{ END }, { GEOM, INT, END }}, 2 };
- + S32 profile = checkArgList(L, constructorArgList, "WallItem", "constructor");
- + if(profile == 1)
- + {
- + setWidth(lua_tointeger(L, -1));
- + lua_pop(L, 1);
- + setGeom(L);
- + }
- + }
- LUAW_CONSTRUCTOR_INITIALIZATIONS;
- }
- @@ -571,6 +584,8 @@
- /////
- // Lua interface
- /**
- + * @luafunc WallItem::WallItem()
- + * @luafunc WallItem::WallItem(geom, thickness)
- * @luaclass WallItem
- * @brief Traditional wall item.
- * @descr A %WallItem is a traditional wall consisting of a series of straight-line segments. WallItems have a width setting that
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/game.cpp
- --- a/zap/game.cpp Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/game.cpp Sun Jan 13 11:34:27 2013 +0100
- @@ -141,7 +141,6 @@
- mNetInterface = new GameNetInterface(theBindAddress, this);
- mHaveTriedToConnectToMaster = false;
- - mDoAnonymousMasterConnection = false;
- mNameToAddressThread = NULL;
- @@ -302,10 +301,9 @@
- }
- -void Game::setReadyToConnectToMaster(bool ready, bool doAnonymous)
- +void Game::setReadyToConnectToMaster(bool ready)
- {
- mReadyToConnectToMaster = ready;
- - mDoAnonymousMasterConnection = doAnonymous;
- }
- @@ -452,6 +450,18 @@
- }
- +void Game::runAnonymousMasterRequest(MasterConnectionCallback callback)
- +{
- + TNLAssert(mAnonymousMasterServerConnection.isNull(), "An anonymous master connection is still open!");
- +
- + // Create a new anonymous connection and set a callback method
- + // You need to make sure to remember to put terminateIfAnonymous() into the master
- + // response RPC that this callback calls
- + mAnonymousMasterServerConnection = new AnonymousMasterServerConnection(this);
- + mAnonymousMasterServerConnection->setConnectionCallback(callback);
- +}
- +
- +
- GameType *Game::getGameType() const
- {
- return mGameType; // This is a safePtr, so it can be NULL, but will never point off into space
- @@ -935,10 +945,6 @@
- TNLAssert(!mConnectionToMaster.isValid(), "Already have connection to master!");
- mConnectionToMaster = new MasterServerConnection(this);
- - // Are we doing an anonymous connection?
- - if(mDoAnonymousMasterConnection)
- - mConnectionToMaster->setConnectionType(MasterConnectionTypeAnonymous);
- -
- mConnectionToMaster->connect(mNetInterface, mNameToAddressThread->mAddress);
- }
- @@ -953,6 +959,46 @@
- else
- mNextMasterTryTime -= timeDelta;
- }
- +
- + processAnonymousMasterConnection();
- +}
- +
- +
- +void Game::processAnonymousMasterConnection()
- +{
- + // Connection doesn't exist yet
- + if(!mAnonymousMasterServerConnection.isValid())
- + return;
- +
- + // Connection has already been initiated
- + if(mAnonymousMasterServerConnection->isInitiator())
- + return;
- +
- + // Try to open a socket to master server
- + if(!mNameToAddressThread)
- + {
- + Vector<string> *masterServerList = mSettings->getMasterServerList();
- +
- + // No master server addresses?
- + if(masterServerList->size() == 0)
- + return;
- +
- + const char *addr = masterServerList->get(0).c_str();
- +
- + mNameToAddressThread = new NameToAddressThread(addr);
- + mNameToAddressThread->start();
- + }
- + else
- + {
- + if(mNameToAddressThread->mDone)
- + {
- + if(mNameToAddressThread->mAddress.isValid())
- + mAnonymousMasterServerConnection->connect(mNetInterface, mNameToAddressThread->mAddress);
- +
- + delete mNameToAddressThread;
- + mNameToAddressThread = NULL;
- + }
- + }
- }
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/game.h
- --- a/zap/game.h Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/game.h Sun Jan 13 11:34:27 2013 +0100
- @@ -110,6 +110,7 @@
- ////////////////////////////////////////
- // Some forward declarations
- +class AnonymousMasterServerConnection;
- class MasterServerConnection;
- class GameNetInterface;
- class GameType;
- @@ -128,6 +129,8 @@
- struct IniSettings;
- +typedef void (MasterServerConnection::*MasterConnectionCallback)();
- +
- // Modes the player could be in during the game
- enum UIMode {
- PlayMode, // Playing
- @@ -200,7 +203,6 @@
- U32 mNextMasterTryTime;
- bool mReadyToConnectToMaster;
- - bool mDoAnonymousMasterConnection;
- Vector<Robot *> mRobots; // Grand master list of all robots in the current game
- Rect mWorldExtents; // Extents of everything
- @@ -229,6 +231,10 @@
- RefPtr<GameNetInterface> mNetInterface;
- SafePtr<MasterServerConnection> mConnectionToMaster;
- +
- + // Not really a queue, but good enough for now!
- + SafePtr<AnonymousMasterServerConnection> mAnonymousMasterServerConnection;
- +
- SafePtr<GameType> mGameType;
- bool mGameSuspended; // True if we're in "suspended animation" mode
- @@ -339,6 +345,9 @@
- void checkConnectionToMaster(U32 timeDelta);
- MasterServerConnection *getConnectionToMaster();
- + void runAnonymousMasterRequest(MasterConnectionCallback callback);
- + void processAnonymousMasterConnection();
- +
- GameNetInterface *getNetInterface();
- virtual GridDatabase *getGameObjDatabase();
- @@ -382,7 +391,7 @@
- void resetMasterConnectTimer();
- - void setReadyToConnectToMaster(bool ready, bool doAnonymous = false);
- + void setReadyToConnectToMaster(bool ready);
- // Objects in a given level, used for status bar. On server it's objects loaded from file, on client, it's objects dl'ed from server.
- S32 mObjectsLoaded;
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/luaLevelGenerator.cpp
- --- a/zap/luaLevelGenerator.cpp Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/luaLevelGenerator.cpp Sun Jan 13 11:34:27 2013 +0100
- @@ -394,7 +394,7 @@
- gt->sendChatFromController(message);
- // Fire our event handler
- - EventManager::get()->fireEvent(getScriptId(), EventManager::MsgReceivedEvent, message, NULL, true);
- + EventManager::get()->fireEvent(this, EventManager::MsgReceivedEvent, message, NULL, true);
- }
- return 0;
- @@ -438,7 +438,10 @@
- S32 LuaLevelGenerator::unsubscribe(lua_State *L) { return doUnsubscribe(L); }
- -const LuaFunctionProfile LuaLevelGenerator::functionArgs[] = { NULL, {{{ }}, 0 } };
- +const LuaFunctionProfile LuaLevelGenerator::functionArgs[] =
- +{
- + { NULL, {{{ }}, 0 } }
- +};
- REGISTER_LUA_CLASS(LuaLevelGenerator);
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/masterConnection.cpp
- --- a/zap/masterConnection.cpp Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/masterConnection.cpp Sun Jan 13 11:34:27 2013 +0100
- @@ -74,7 +74,13 @@
- MasterServerConnection::MasterServerConnection()
- {
- - TNLAssert(false, "We need a default constructor, but we never actually use it!");
- + TNLAssert(false, "We need a default constructor, but we never actually use it!");
- +}
- +
- +
- +MasterServerConnection::~MasterServerConnection()
- +{
- + // Do nothing
- }
- @@ -245,6 +251,8 @@
- setMasterName(masterName.getString());
- static_cast<ClientGame *>(mGame)->setMOTD(motdString.getString());
- +
- + terminateIfAnonymous();
- }
- @@ -512,6 +520,57 @@
- }
- +void MasterServerConnection::terminateIfAnonymous()
- +{
- + if(mConnectionType != MasterConnectionTypeAnonymous)
- + return;
- +
- + // Actions performed on an anonymous connection should terminate the connection
- + disconnect(ReasonAnonymous, "");
- +}
- +
- +
- +AnonymousMasterServerConnection::AnonymousMasterServerConnection(Game *game) : Parent(game)
- +{
- + mConnectionType = MasterConnectionTypeAnonymous;
- + mConnectionCallback = NULL;
- +}
- +
- +
- +AnonymousMasterServerConnection::~AnonymousMasterServerConnection()
- +{
- + // Do nothing
- +}
- +
- +
- +// Set a function to call upon establishing a connection
- +void AnonymousMasterServerConnection::setConnectionCallback(MasterConnectionCallback callback)
- +{
- + mConnectionCallback = callback;
- +}
- +
- +
- +MasterConnectionCallback AnonymousMasterServerConnection::getConnectionCallback()
- +{
- + return mConnectionCallback;
- +}
- +
- +
- +void AnonymousMasterServerConnection::onConnectionEstablished()
- +{
- + Parent::onConnectionEstablished();
- +
- + // Run the callback
- + // This uses some funky syntax. See sections 2.1 and 2.5 of:
- + // http://www.newty.de/fpt/fpt.html#chapter2
- + if(mConnectionCallback)
- + {
- + (*this.*mConnectionCallback)();
- + mConnectionCallback = NULL;
- + }
- +}
- +
- +
- };
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/masterConnection.h
- --- a/zap/masterConnection.h Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/masterConnection.h Sun Jan 13 11:34:27 2013 +0100
- @@ -50,11 +50,15 @@
- Game *mGame;
- string mMasterName;
- + void terminateIfAnonymous();
- +
- +protected:
- MasterConnectionType mConnectionType;
- public:
- MasterServerConnection(Game *game); // Constructor
- - MasterServerConnection();
- + MasterServerConnection(); // Default Constructor required by TNL for some reason..
- + virtual ~MasterServerConnection(); // Destructor
- void setConnectionType(MasterConnectionType type);
- MasterConnectionType getConnectionType();
- @@ -104,13 +108,33 @@
- RangedU32<0,AuthenticationStatusCount> status, Int<BADGE_COUNT> badges));
- void writeConnectRequest(BitStream *bstream);
- - void onConnectionEstablished();
- + virtual void onConnectionEstablished();
- void onConnectionTerminated(TerminationReason r, const char *string); // An existing connection has been terminated
- void onConnectTerminated(TerminationReason r, const char *string); // A still-being-established connection has been terminated
- TNL_DECLARE_NETCONNECTION(MasterServerConnection);
- };
- +
- +typedef void (MasterServerConnection::*MasterConnectionCallback)();
- +
- +class AnonymousMasterServerConnection : public MasterServerConnection
- +{
- + typedef MasterServerConnection Parent;
- +
- +private:
- + MasterConnectionCallback mConnectionCallback;
- +
- +public:
- + AnonymousMasterServerConnection(Game *game); // Constructor
- + virtual ~AnonymousMasterServerConnection();
- +
- + void setConnectionCallback(MasterConnectionCallback callback);
- + MasterConnectionCallback getConnectionCallback();
- +
- + void onConnectionEstablished();
- +};
- +
- };
- #endif
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/projectile.cpp
- --- a/zap/projectile.cpp Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/projectile.cpp Sun Jan 13 11:34:27 2013 +0100
- @@ -1017,7 +1017,20 @@
- // Combined Lua / C++ default constructor -- used in Lua and editor
- SpyBug::SpyBug(lua_State *L) : Burst(Point(0,0), Point(0,0), NULL)
- {
- - initialize(Point(0,0), NULL);
- + if(L)
- + {
- + static LuaFunctionArgList constructorArgList = { {{ END }, { GEOM, TEAM_INDX, END }}, 2 };
- + S32 profile = checkArgList(L, constructorArgList, "SpyBug", "constructor");
- +
- + if(profile == 0)
- + initialize(Point(0,0), NULL);
- + else if(profile == 1)
- + {
- + initialize(Point(0,0), NULL);
- + setPos(getPointOrXY(L, 1));
- + setTeam(getInt(L, 2));
- + }
- + }
- }
- @@ -1240,6 +1253,14 @@
- /////
- // Lua interface
- +/**
- + * @luafunc SpyBug::SpyBug()
- + * @luafunc SpyBug::SpyBug(geom, team)
- + * @luaclass SpyBug
- + * @brief Monitors a section of the map and will show enemy ships there.
- + * @descr Can only be used/created if the Sensor module is selected.
- + * Makes surrounding areas of the commander's map visible to player and teammates.
- + */
- // Fn name Param profiles Profile count
- #define LUA_METHODS(CLASS, METHOD) \
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/robot.cpp
- --- a/zap/robot.cpp Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/robot.cpp Sun Jan 13 11:34:27 2013 +0100
- @@ -108,7 +108,7 @@
- // Server only from here on down
- if(getGame()) // can be NULL if this robot was never added to game (bad / missing robot file)
- {
- - EventManager::get()->fireEvent(getScriptId(), EventManager::PlayerLeftEvent, getPlayerInfo());
- + EventManager::get()->fireEvent(this, EventManager::PlayerLeftEvent, getPlayerInfo());
- if(getGame()->getGameType())
- getGame()->getGameType()->serverRemoveClient(mClientInfo);
- @@ -172,7 +172,7 @@
- return false;
- // Pass true so that if this bot doesn't have a TickEvent handler, we don't print a message
- - EventManager::get()->subscribe(getScriptId(), EventManager::TickEvent, RobotContext, true);
- + EventManager::get()->subscribe(this, EventManager::TickEvent, RobotContext, true);
- mSubscriptions[EventManager::TickEvent] = true;
- @@ -298,7 +298,7 @@
- game->addBot(this); // Add this robot to the list of all robots (can't do this in constructor or else it gets run on client side too...)
- - EventManager::get()->fireEvent(getScriptId(), EventManager::PlayerJoinedEvent, getPlayerInfo());
- + EventManager::get()->fireEvent(this, EventManager::PlayerJoinedEvent, getPlayerInfo());
- }
- @@ -1092,7 +1092,7 @@
- gt->sendChatFromRobot(true, message, getClientInfo());
- // Fire our event handler
- - EventManager::get()->fireEvent(getScriptId(), EventManager::MsgReceivedEvent, message, getPlayerInfo(), true);
- + EventManager::get()->fireEvent(this, EventManager::MsgReceivedEvent, message, getPlayerInfo(), true);
- }
- return 0;
- @@ -1112,7 +1112,7 @@
- gt->sendChatFromRobot(false, message, getClientInfo());
- // Fire our event handler
- - EventManager::get()->fireEvent(getScriptId(), EventManager::MsgReceivedEvent, message, getPlayerInfo(), false);
- + EventManager::get()->fireEvent(this, EventManager::MsgReceivedEvent, message, getPlayerInfo(), false);
- }
- return 0;
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/speedZone.cpp
- --- a/zap/speedZone.cpp Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/speedZone.cpp Sun Jan 13 11:34:27 2013 +0100
- @@ -63,6 +63,9 @@
- // Combined C++/Lua constructor
- SpeedZone::SpeedZone(lua_State *L)
- {
- + static LuaFunctionArgList constructorArgList = { {{ END }, { GEOM, END }, { GEOM, NUM, END }}, 3 };
- + S32 profile = checkArgList(L, constructorArgList, "SpeedZone", "constructor");
- +
- mNetFlags.set(Ghostable);
- mObjectTypeNumber = SpeedZoneTypeNumber;
- @@ -72,6 +75,14 @@
- mUnpackInit = 0; // Some form of counter, to know that it is a rotating speed zone
- preparePoints(); // If this is constructed by Lua, we need to have some default geometry in place
- +
- + if(L && profile == 1)
- + setPos(getPointOrXY(L, 1));
- + else if(L && profile == 2)
- + {
- + setPos(getPointOrXY(L, 1));
- + setSpeed(getInt(L, 2));
- + }
- LUAW_CONSTRUCTOR_INITIALIZATIONS;
- }
- @@ -530,6 +541,9 @@
- //// Lua methods
- /**
- + * @luafunc SpeedZone::SpeedZone()
- + * @luafunc SpeedZone::SpeedZone(geom)
- + * @luafunc SpeedZone::SpeedZone(geom, speed)
- * @luaclass SpeedZone
- * @brief Propels ships at high speed.
- * @descr SpeedZones are game objects that propel ships around a level. Each %SpeedZone has a direction point
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/teleporter.cpp
- --- a/zap/teleporter.cpp Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/teleporter.cpp Sun Jan 13 11:34:27 2013 +0100
- @@ -84,14 +84,13 @@
- void DestManager::addDest(const Point &dest)
- {
- + TNLAssert(mOwner, "We need an owner here!");
- mDests.push_back(dest);
- -
- if(mDests.size() == 1) // Just added the first dest
- {
- mOwner->setVert(dest, 1);
- mOwner->updateExtentInDatabase();
- }
- -
- // If we're the server, update the clients
- if(mOwner->getGame() && mOwner->getGame()->isServer())
- mOwner->s2cAddDestination(dest);
- @@ -176,7 +175,16 @@
- // Combined default C++/Lua constructor
- Teleporter::Teleporter(lua_State *L)
- {
- - initialize(Point(0,0), Point(0,0), NULL);
- + initialize(Point(0,0),Point(0,0),NULL);
- + // TODO: Fix this one too -- intiailze needs to be refactored because who knows
- + // how many points the teleporter is getting? could be 1, could be 2, could be many
- + if(L)
- + {
- + static LuaFunctionArgList constructorArgList = { {{ END }, { GEOM, END }}, 2 };
- + S32 profile = checkArgList(L, constructorArgList, "Teleporter", "constructor");
- + if(profile == 1)
- + setPos(getPointOrXY(L, 1));
- + }
- }
- @@ -857,6 +865,8 @@
- //// Lua methods
- /**
- + * @luafunc Teleporter::Teleporter()
- + * @luafunc Teleporter::Teleporter(geom)
- * @luaclass Teleporter
- * @brief Instantly transports ships from here to there.
- * @descr A %Teleporter represents the basic teleporter object. Every teleporter has an intake location
- diff -r a8a4d5213b1e -r f6c2d27eb104 zap/textItem.cpp
- --- a/zap/textItem.cpp Sat Jan 12 13:30:52 2013 +0100
- +++ b/zap/textItem.cpp Sun Jan 13 11:34:27 2013 +0100
- @@ -53,6 +53,9 @@
- // Combined Lua / C++ constructor
- TextItem::TextItem(lua_State *L)
- {
- + static LuaFunctionArgList constructorArgList = { {{ END }, { GEOM, STR, END }}, 2 };
- + S32 profile = checkArgList(L, constructorArgList, "Spawn", "constructor");
- +
- mNetFlags.set(Ghostable);
- mObjectTypeNumber = TextItemTypeNumber;
- @@ -60,6 +63,12 @@
- mSize = 20;
- LUAW_CONSTRUCTOR_INITIALIZATIONS;
- +
- + if(L && profile == 1)
- + {
- + setPos(getPointOrXY(L, 1));
- + setText(getString(L, 2));
- + }
- }
- @@ -426,6 +435,8 @@
- //// Lua methods
- /**
- + * @luafunc TextItem::TextItem()
- + * @luafunc TextItem::TextItem(geom, text)
- * @luaclass TextItem
- * @brief Display text message in level.
- * @descr A %TextItem displays text in a level. If the %TextItem belongs to a team, it is only visible to players on that team.
Advertisement
Add Comment
Please, Sign In to add comment