Add prefixes to enum values and fix style issues
authorkwolekr <kwolekr@minetest.net>
Sat, 28 Jun 2014 06:02:38 +0000 (02:02 -0400)
committerkwolekr <kwolekr@minetest.net>
Sat, 28 Jun 2014 06:02:38 +0000 (02:02 -0400)
src/clientiface.cpp
src/clientiface.h
src/connection.cpp
src/connection.h
src/server.cpp
src/server.h

index 626e5da74270bbd8b13cc9338c2dc8550da56e00..2841b212f95877cd02133d84b9f6cf4b18004ba2 100644 (file)
@@ -34,6 +34,25 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "main.h"                      // for g_settings
 
+const char *ClientInterface::statenames[] = {
+       "Invalid",
+       "Disconnecting",
+       "Denied",
+       "Created",
+       "InitSent",
+       "InitDone",
+       "DefinitionsSent",
+       "Active"
+};
+
+
+
+std::string ClientInterface::state2Name(ClientState state)
+{
+       return statenames[state];
+}
+
+
 void RemoteClient::GetNextBlocks(
                ServerEnvironment *env,
                EmergeManager * emerge,
@@ -402,50 +421,42 @@ void RemoteClient::notifyEvent(ClientStateEvent event)
        std::ostringstream myerror;
        switch (m_state)
        {
-       case Invalid:
+       case CS_Invalid:
                //intentionally do nothing
                break;
-
-       case Created:
+       case CS_Created:
                switch(event)
                {
-               case Init:
-                       m_state = InitSent;
+               case CSE_Init:
+                       m_state = CS_InitSent;
                        break;
-
-               case Disconnect:
-                       m_state = Disconnecting;
+               case CSE_Disconnect:
+                       m_state = CS_Disconnecting;
                        break;
-
-               case SetDenied:
-                       m_state = Denied;
+               case CSE_SetDenied:
+                       m_state = CS_Denied;
                        break;
-
                /* GotInit2 SetDefinitionsSent SetMediaSent */
                default:
                        myerror << "Created: Invalid client state transition! " << event;
                        throw ClientStateError(myerror.str());
                }
                break;
-
-       case Denied:
+       case CS_Denied:
                /* don't do anything if in denied state */
                break;
-
-       case InitSent:
+       case CS_InitSent:
                switch(event)
                {
-               case GotInit2:
+               case CSE_GotInit2:
                        confirmSerializationVersion();
-                       m_state = InitDone;
+                       m_state = CS_InitDone;
                        break;
-
-               case Disconnect:
-                       m_state = Disconnecting;
+               case CSE_Disconnect:
+                       m_state = CS_Disconnecting;
                        break;
-
-               case SetDenied:
-                       m_state = Denied;
+               case CSE_SetDenied:
+                       m_state = CS_Denied;
                        break;
 
                /* Init SetDefinitionsSent SetMediaSent */
@@ -455,19 +466,17 @@ void RemoteClient::notifyEvent(ClientStateEvent event)
                }
                break;
 
-       case InitDone:
+       case CS_InitDone:
                switch(event)
                {
-               case SetDefinitionsSent:
-                       m_state = DefinitionsSent;
+               case CSE_SetDefinitionsSent:
+                       m_state = CS_DefinitionsSent;
                        break;
-
-               case Disconnect:
-                       m_state = Disconnecting;
+               case CSE_Disconnect:
+                       m_state = CS_Disconnecting;
                        break;
-
-               case SetDenied:
-                       m_state = Denied;
+               case CSE_SetDenied:
+                       m_state = CS_Denied;
                        break;
 
                /* Init GotInit2 SetMediaSent */
@@ -476,40 +485,33 @@ void RemoteClient::notifyEvent(ClientStateEvent event)
                        throw ClientStateError(myerror.str());
                }
                break;
-
-       case DefinitionsSent:
+       case CS_DefinitionsSent:
                switch(event)
                {
-               case SetClientReady:
-                       m_state = Active;
+               case CSE_SetClientReady:
+                       m_state = CS_Active;
                        break;
-
-               case Disconnect:
-                       m_state = Disconnecting;
+               case CSE_Disconnect:
+                       m_state = CS_Disconnecting;
                        break;
-
-               case SetDenied:
-                       m_state = Denied;
+               case CSE_SetDenied:
+                       m_state = CS_Denied;
                        break;
-
                /* Init GotInit2 SetDefinitionsSent */
                default:
                        myerror << "DefinitionsSent: Invalid client state transition! " << event;
                        throw ClientStateError(myerror.str());
                }
                break;
-
-       case Active:
+       case CS_Active:
                switch(event)
                {
-               case SetDenied:
-                       m_state = Denied;
+               case CSE_SetDenied:
+                       m_state = CS_Denied;
                        break;
-
-               case Disconnect:
-                       m_state = Disconnecting;
+               case CSE_Disconnect:
+                       m_state = CS_Disconnecting;
                        break;
-
                /* Init GotInit2 SetDefinitionsSent SetMediaSent SetDenied */
                default:
                        myerror << "Active: Invalid client state transition! " << event;
@@ -517,8 +519,7 @@ void RemoteClient::notifyEvent(ClientStateEvent event)
                        break;
                }
                break;
-
-       case Disconnecting:
+       case CS_Disconnecting:
                /* we are already disconnecting */
                break;
        }
@@ -680,7 +681,7 @@ ClientState ClientInterface::getClientState(u16 peer_id)
        // The client may not exist; clients are immediately removed if their
        // access is denied, and this event occurs later then.
        if(n == m_clients.end())
-               return Invalid;
+               return CS_Invalid;
 
        return n->second->getState();
 }
@@ -762,7 +763,9 @@ void ClientInterface::event(u16 peer_id, ClientStateEvent event)
                n->second->notifyEvent(event);
        }
 
-       if ((event == SetClientReady) || (event == Disconnect) || (event == SetDenied))
+       if ((event == CSE_SetClientReady) ||
+               (event == CSE_Disconnect)     ||
+               (event == CSE_SetDenied))
        {
                UpdatePlayerList();
        }
index 89e0f41b90dd407199989c11a4d12fe4aa579b2e..5452ccddbdf5a08cb642ac35d3f4cab2adc8c129 100644 (file)
@@ -145,35 +145,24 @@ namespace con {
 
 enum ClientState
 {
-       Invalid,
-       Disconnecting,
-       Denied,
-       Created,
-       InitSent,
-       InitDone,
-       DefinitionsSent,
-       Active
-};
-
-static const char* statenames[] = {
-       "Invalid",
-       "Disconnecting",
-       "Denied",
-       "Created",
-       "InitSent",
-       "InitDone",
-       "DefinitionsSent",
-       "Active"
+       CS_Invalid,
+       CS_Disconnecting,
+       CS_Denied,
+       CS_Created,
+       CS_InitSent,
+       CS_InitDone,
+       CS_DefinitionsSent,
+       CS_Active
 };
 
 enum ClientStateEvent
 {
-       Init,
-       GotInit2,
-       SetDenied,
-       SetDefinitionsSent,
-       SetClientReady,
-       Disconnect
+       CSE_Init,
+       CSE_GotInit2,
+       CSE_SetDenied,
+       CSE_SetDefinitionsSent,
+       CSE_SetClientReady,
+       CSE_Disconnect
 };
 
 /*
@@ -217,7 +206,7 @@ public:
                net_proto_version(0),
                m_time_from_building(9999),
                m_pending_serialization_version(SER_FMT_VER_INVALID),
-               m_state(Created),
+               m_state(CS_Created),
                m_nearest_unsent_d(0),
                m_nearest_unsent_reset_timer(0.0),
                m_excess_gotblocks(0),
@@ -390,7 +379,7 @@ public:
        void step(float dtime);
 
        /* get list of active client id's */
-       std::list<u16> getClientIDs(ClientState min_state=Active);
+       std::list<u16> getClientIDs(ClientState min_state=CS_Active);
 
        /* get list of client player names */
        std::vector<std::string> getPlayerNames();
@@ -408,10 +397,10 @@ public:
        void CreateClient(u16 peer_id);
 
        /* get a client by peer_id */
-       RemoteClient* getClientNoEx(u16 peer_id,  ClientState state_min=Active);
+       RemoteClient* getClientNoEx(u16 peer_id,  ClientState state_min=CS_Active);
 
        /* get client by peer_id (make sure you have list lock before!*/
-       RemoteClient* lockedGetClientNoEx(u16 peer_id,  ClientState state_min=Active);
+       RemoteClient* lockedGetClientNoEx(u16 peer_id,  ClientState state_min=CS_Active);
 
        /* get state of client by id*/
        ClientState getClientState(u16 peer_id);
@@ -432,10 +421,7 @@ public:
        void setEnv(ServerEnvironment* env)
        { assert(m_env == 0); m_env = env; }
 
-       static std::string state2Name(ClientState state) {
-               assert((int) state < CI_ARRAYSIZE(statenames));
-               return statenames[state];
-       }
+       static std::string state2Name(ClientState state);
 
 protected:
        //TODO find way to avoid this functions
@@ -463,6 +449,8 @@ private:
        JMutex m_env_mutex;
 
        float m_print_info_timer;
+       
+       static const char *statenames[];
 };
 
 #endif
index ef6d80394e1108f4ab38eda01e1dac6b6bf46ab5..76cb7b8b7e48a5b2de8a18d360b286cb26ddc0bd 100644 (file)
@@ -1000,7 +1000,7 @@ UDPPeer::UDPPeer(u16 a_id, Address a_address, Connection* connection) :
 
 bool UDPPeer::getAddress(MTProtocols type,Address& toset)
 {
-       if ((type == UDP) || (type == MINETEST_RELIABLE_UDP) || (type == PRIMARY))
+       if ((type == MTP_UDP) || (type == MTP_MINETEST_RELIABLE_UDP) || (type == MTP_PRIMARY))
        {
                toset = address;
                return true;
@@ -1526,7 +1526,7 @@ bool ConnectionSendThread::rawSendAsPacket(u16 peer_id, u8 channelnum,
 
                SharedBuffer<u8> reliable = makeReliablePacket(data, seqnum);
                Address peer_address;
-               peer->getAddress(MINETEST_RELIABLE_UDP,peer_address);
+               peer->getAddress(MTP_MINETEST_RELIABLE_UDP, peer_address);
 
                // Add base headers and make a packet
                BufferedPacket p = con::makePacket(peer_address, reliable,
@@ -1556,7 +1556,7 @@ bool ConnectionSendThread::rawSendAsPacket(u16 peer_id, u8 channelnum,
        {
                Address peer_address;
 
-               if (peer->getAddress(UDP,peer_address))
+               if (peer->getAddress(MTP_UDP, peer_address))
                {
                        // Add base headers and make a packet
                        BufferedPacket p = con::makePacket(peer_address, data,
@@ -2165,7 +2165,7 @@ void ConnectionReceiveThread::receive()
                /* The peer was not found in our lists. Add it. */
                if(peer_id == PEER_ID_INEXISTENT)
                {
-                       peer_id = m_connection->createPeer(sender,MINETEST_RELIABLE_UDP,0);
+                       peer_id = m_connection->createPeer(sender, MTP_MINETEST_RELIABLE_UDP, 0);
                }
 
                PeerHelper peer = m_connection->getPeerNoEx(peer_id);
@@ -2181,7 +2181,7 @@ void ConnectionReceiveThread::receive()
 
                Address peer_address;
 
-               if (peer->getAddress(UDP,peer_address)) {
+               if (peer->getAddress(MTP_UDP, peer_address)) {
                        if (peer_address != sender) {
                                LOG(derr_con<<m_connection->getDesc()
                                                <<m_connection->getDesc()
@@ -2469,7 +2469,7 @@ SharedBuffer<u8> ConnectionReceiveThread::processPacket(Channel *channel,
        {
                Address peer_address;
 
-               if (peer->getAddress(UDP,peer_address)) {
+               if (peer->getAddress(MTP_UDP, peer_address)) {
 
                        // We have to create a packet again for buffering
                        // This isn't actually too bad an idea.
@@ -2552,7 +2552,7 @@ SharedBuffer<u8> ConnectionReceiveThread::processPacket(Channel *channel,
                        Address peer_address;
 
                        // this is a reliable packet so we have a udp address for sure
-                       peer->getAddress(MINETEST_RELIABLE_UDP,peer_address);
+                       peer->getAddress(MTP_MINETEST_RELIABLE_UDP, peer_address);
                        // This one comes later, buffer it.
                        // Actually we have to make a packet to buffer one.
                        // Well, we have all the ingredients, so just do it.
@@ -2754,10 +2754,10 @@ u16 Connection::lookupPeer(Address& sender)
 
                Address tocheck;
 
-               if ((peer->getAddress(MINETEST_RELIABLE_UDP,tocheck)) && (tocheck == sender))
+               if ((peer->getAddress(MTP_MINETEST_RELIABLE_UDP, tocheck)) && (tocheck == sender))
                        return peer->id;
 
-               if ((peer->getAddress(UDP,tocheck)) && (tocheck == sender))
+               if ((peer->getAddress(MTP_UDP, tocheck)) && (tocheck == sender))
                        return peer->id;
        }
 
@@ -2791,7 +2791,7 @@ bool Connection::deletePeer(u16 peer_id, bool timeout)
 
        Address peer_address;
        //any peer has a primary address this never fails!
-       peer->getAddress(PRIMARY,peer_address);
+       peer->getAddress(MTP_PRIMARY, peer_address);
        // Create event
        ConnectionEvent e;
        e.peerRemoved(peer_id, timeout, peer_address);
@@ -2930,7 +2930,7 @@ Address Connection::GetPeerAddress(u16 peer_id)
        if (!peer)
                throw PeerNotFoundException("No address for peer found!");
        Address peer_address;
-       peer->getAddress(PRIMARY,peer_address);
+       peer->getAddress(MTP_PRIMARY, peer_address);
        return peer_address;
 }
 
index 338ee964ce36378ff4aff16579ef4255aa6befe2..b025a4dfc000857e24ada71ee89354fe1b6a90d6 100644 (file)
@@ -120,9 +120,9 @@ public:
 };
 
 typedef enum MTProtocols {
-       PRIMARY,
-       UDP,
-       MINETEST_RELIABLE_UDP
+       MTP_PRIMARY,
+       MTP_UDP,
+       MTP_MINETEST_RELIABLE_UDP
 } MTProtocols;
 
 #define SEQNUM_MAX 65535
index 516a9d2f9c32b3a4cd51d04d5bad7b1dad7802ef..58ecb23b46c796ed03bf6d509983789927a6290b 100644 (file)
@@ -714,7 +714,7 @@ void Server::AsyncRunStep(bool initial_step)
 
                        // If definitions and textures have not been sent, don't
                        // send objects either
-                       if (client->getState() < DefinitionsSent)
+                       if (client->getState() < CS_DefinitionsSent)
                                continue;
 
                        Player *player = m_env->getPlayer(client->peer_id);
@@ -1169,7 +1169,7 @@ PlayerSAO* Server::StageTwoClientInit(u16 peer_id)
        std::string playername = "";
        PlayerSAO *playersao = NULL;
        m_clients.Lock();
-       RemoteClient* client = m_clients.lockedGetClientNoEx(peer_id,InitDone);
+       RemoteClient* client = m_clients.lockedGetClientNoEx(peer_id, CS_InitDone);
        if (client != NULL) {
                playername = client->getName();
                playersao = emergePlayer(playername.c_str(), peer_id);
@@ -1320,10 +1320,10 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                if(datasize < 2+1+PLAYERNAME_SIZE)
                        return;
 
-               RemoteClient* client = getClient(peer_id,Created);
+               RemoteClient* client = getClient(peer_id, CS_Created);
 
                // If net_proto_version is set, this client has already been handled
-               if(client->getState() > Created)
+               if(client->getState() > CS_Created)
                {
                        verbosestream<<"Server: Ignoring multiple TOSERVER_INITs from "
                                        <<addr_s<<" (peer_id="<<peer_id<<")"<<std::endl;
@@ -1522,7 +1522,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
 
                // Enforce user limit.
                // Don't enforce for users that have some admin right
-               if(m_clients.getClientIDs(Created).size() >= g_settings->getU16("max_users") &&
+               if(m_clients.getClientIDs(CS_Created).size() >= g_settings->getU16("max_users") &&
                                !checkPriv(playername, "server") &&
                                !checkPriv(playername, "ban") &&
                                !checkPriv(playername, "privs") &&
@@ -1605,7 +1605,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
 
                        // Send as reliable
                        m_clients.send(peer_id, 0, reply, true);
-                       m_clients.event(peer_id, Init);
+                       m_clients.event(peer_id, CSE_Init);
                }
 
                return;
@@ -1617,7 +1617,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                verbosestream<<"Server: Got TOSERVER_INIT2 from "
                                <<peer_id<<std::endl;
 
-               m_clients.event(peer_id, GotInit2);
+               m_clients.event(peer_id, CSE_GotInit2);
                u16 protocol_version = m_clients.getProtocolVersion(peer_id);
 
 
@@ -1651,7 +1651,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                // Send node definitions
                SendNodeDef(peer_id, m_nodedef, protocol_version);
 
-               m_clients.event(peer_id, SetDefinitionsSent);
+               m_clients.event(peer_id, CSE_SetDefinitionsSent);
 
                // Send media announcement
                sendMediaAnnouncement(peer_id);
@@ -1666,7 +1666,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
 
                ///// begin compatibility code
                if (protocol_version <= 22) {
-                       m_clients.event(peer_id, SetClientReady);
+                       m_clients.event(peer_id, CSE_SetClientReady);
                        m_script->on_joinplayer(playersao);
                }
                ///// end compatibility code
@@ -1681,8 +1681,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                return;
        }
 
-       u8 peer_ser_ver = getClient(peer_id,InitDone)->serialization_version;
-       u16 peer_proto_ver = getClient(peer_id,InitDone)->net_proto_version;
+       u8 peer_ser_ver = getClient(peer_id, CS_InitDone)->serialization_version;
+       u16 peer_proto_ver = getClient(peer_id, CS_InitDone)->net_proto_version;
 
        if(peer_ser_ver == SER_FMT_VER_INVALID)
        {
@@ -1746,7 +1746,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                                data[2], data[3], data[4],
                                std::string((char*) &data[8],(u16) data[6]));
 
-               m_clients.event(peer_id, SetClientReady);
+               m_clients.event(peer_id, CSE_SetClientReady);
                m_script->on_joinplayer(playersao);
 
        }
@@ -1778,7 +1778,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                return;
        }
 
-       if (m_clients.getClientState(peer_id) < Active)
+       if (m_clients.getClientState(peer_id) < CS_Active)
        {
                if (command == TOSERVER_PLAYERPOS) return;
 
@@ -2837,7 +2837,7 @@ void Server::deletingPeer(con::Peer *peer, bool timeout)
        verbosestream<<"Server::deletingPeer(): peer->id="
                        <<peer->id<<", timeout="<<timeout<<std::endl;
 
-       m_clients.event(peer->id,Disconnect);
+       m_clients.event(peer->id, CSE_Disconnect);
        con::PeerChange c;
        c.type = con::PEER_REMOVED;
        c.peer_id = peer->id;
@@ -2866,12 +2866,12 @@ bool Server::getClientInfo(
 {
        *state = m_clients.getClientState(peer_id);
        m_clients.Lock();
-       RemoteClient* client = m_clients.lockedGetClientNoEx(peer_id,Invalid);
+       RemoteClient* client = m_clients.lockedGetClientNoEx(peer_id, CS_Invalid);
 
        if (client == NULL) {
                m_clients.Unlock();
                return false;
-               }
+       }
 
        *uptime = client->uptime();
        *ser_vers = client->serialization_version;
@@ -3841,7 +3841,7 @@ void Server::SendBlocks(float dtime)
                        i = clients.begin();
                        i != clients.end(); ++i)
                {
-                       RemoteClient *client = m_clients.lockedGetClientNoEx(*i,Active);
+                       RemoteClient *client = m_clients.lockedGetClientNoEx(*i, CS_Active);
 
                        if (client == NULL)
                                return;
@@ -3877,7 +3877,7 @@ void Server::SendBlocks(float dtime)
                        continue;
                }
 
-               RemoteClient *client = m_clients.lockedGetClientNoEx(q.peer_id,Active);
+               RemoteClient *client = m_clients.lockedGetClientNoEx(q.peer_id, CS_Active);
 
                if(!client)
                        continue;
@@ -4268,7 +4268,7 @@ void Server::DenyAccess(u16 peer_id, const std::wstring &reason)
        DSTACK(__FUNCTION_NAME);
 
        SendAccessDenied(peer_id, reason);
-       m_clients.event(peer_id,SetDenied);
+       m_clients.event(peer_id, CSE_SetDenied);
        m_con.DisconnectPeer(peer_id);
 }
 
index 4cfc879cdbc0f6197a8b5c30bbc8fa54693abe54..cb0baceced8fd1358980192a9d8ae9b9cd2653e7 100644 (file)
@@ -432,8 +432,8 @@ private:
        void UpdateCrafting(u16 peer_id);
 
        // When called, connection mutex should be locked
-       RemoteClient* getClient(u16 peer_id,ClientState state_min=Active);
-       RemoteClient* getClientNoEx(u16 peer_id,ClientState state_min=Active);
+       RemoteClient* getClient(u16 peer_id,ClientState state_min=CS_Active);
+       RemoteClient* getClientNoEx(u16 peer_id,ClientState state_min=CS_Active);
 
        // When called, environment mutex should be locked
        std::string getPlayerName(u16 peer_id);