#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,
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 */
}
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 */
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;
break;
}
break;
-
- case Disconnecting:
+ case CS_Disconnecting:
/* we are already disconnecting */
break;
}
// 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();
}
n->second->notifyEvent(event);
}
- if ((event == SetClientReady) || (event == Disconnect) || (event == SetDenied))
+ if ((event == CSE_SetClientReady) ||
+ (event == CSE_Disconnect) ||
+ (event == CSE_SetDenied))
{
UpdatePlayerList();
}
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
};
/*
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),
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();
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);
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
JMutex m_env_mutex;
float m_print_info_timer;
+
+ static const char *statenames[];
};
#endif
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;
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,
{
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,
/* 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);
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()
{
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.
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.
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;
}
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);
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;
}
};
typedef enum MTProtocols {
- PRIMARY,
- UDP,
- MINETEST_RELIABLE_UDP
+ MTP_PRIMARY,
+ MTP_UDP,
+ MTP_MINETEST_RELIABLE_UDP
} MTProtocols;
#define SEQNUM_MAX 65535
// 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);
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);
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;
// 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") &&
// 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;
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);
// 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);
///// 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
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)
{
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);
}
return;
}
- if (m_clients.getClientState(peer_id) < Active)
+ if (m_clients.getClientState(peer_id) < CS_Active)
{
if (command == TOSERVER_PLAYERPOS) return;
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;
{
*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;
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;
continue;
}
- RemoteClient *client = m_clients.lockedGetClientNoEx(q.peer_id,Active);
+ RemoteClient *client = m_clients.lockedGetClientNoEx(q.peer_id, CS_Active);
if(!client)
continue;
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);
}
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);