Skip to content
Permalink
Browse files

Add prefixes to enum values and fix style issues

  • Loading branch information
kwolekr committed Jun 28, 2014
1 parent 6ee0db6 commit c91f8b1d251c81dcfc398c9ca2a4d79086212839
Showing with 115 additions and 124 deletions.
  1. +59 −56 src/clientiface.cpp
  2. +21 −33 src/clientiface.h
  3. +11 −11 src/connection.cpp
  4. +3 −3 src/connection.h
  5. +19 −19 src/server.cpp
  6. +2 −2 src/server.h
@@ -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,49 +485,41 @@ 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;
throw ClientStateError(myerror.str());
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();
}
@@ -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 @@ class RemoteClient
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 @@ class ClientInterface {
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 @@ class ClientInterface {
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 @@ class ClientInterface {
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 @@ class ClientInterface {
JMutex m_env_mutex;

float m_print_info_timer;

static const char *statenames[];
};

#endif
@@ -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;
}

0 comments on commit c91f8b1

Please sign in to comment.
You can’t perform that action at this time.