Rewritten cAuthenticator to make use of the new cIsThread architecture - now authentication runs in a single separate thread for all clients;
Global player-kicking function (cServer, cRoot); More char * -> AString conversion git-svn-id: http://mc-server.googlecode.com/svn/trunk@221 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
@@ -48,6 +48,10 @@ bool g_bWaterPhysics = false;
|
||||
|
||||
typedef std::list< cClientHandle* > ClientList;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct cServer::sServerState
|
||||
{
|
||||
sServerState()
|
||||
@@ -67,12 +71,20 @@ struct cServer::sServerState
|
||||
std::string ServerID;
|
||||
};
|
||||
|
||||
cServer*cServer::GetServer()
|
||||
|
||||
|
||||
|
||||
|
||||
cServer * cServer::GetServer()
|
||||
{
|
||||
LOGWARN("WARNING: Using deprecated function cServer::GetServer() use cRoot::Get()->GetServer() instead!");
|
||||
return cRoot::Get()->GetServer();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cServer::ServerListenThread( void *a_Args )
|
||||
{
|
||||
LOG("ServerListenThread");
|
||||
@@ -84,6 +96,10 @@ void cServer::ServerListenThread( void *a_Args )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
std::string GetWSAError()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
@@ -126,6 +142,10 @@ std::string GetWSAError()
|
||||
return "No Error";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cServer::InitServer( int a_Port )
|
||||
{
|
||||
if( m_bIsConnected )
|
||||
@@ -135,7 +155,7 @@ bool cServer::InitServer( int a_Port )
|
||||
}
|
||||
|
||||
printf("/============================\\\n");
|
||||
printf("| Minecraft Alpha Server |\n");
|
||||
printf("| Custom Minecraft Server |\n");
|
||||
printf("| Created by Kevin Bansberg |\n");
|
||||
printf("| A.K.A. |\n");
|
||||
printf("| FakeTruth |\n");
|
||||
@@ -222,6 +242,10 @@ bool cServer::InitServer( int a_Port )
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cServer::cServer()
|
||||
: m_pState( new sServerState )
|
||||
, m_Millisecondsf( 0 )
|
||||
@@ -232,6 +256,10 @@ cServer::cServer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cServer::~cServer()
|
||||
{
|
||||
if( m_pState->SListenClient ) m_pState->SListenClient.CloseSocket();
|
||||
@@ -245,6 +273,10 @@ cServer::~cServer()
|
||||
delete m_pState;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO - Need to modify this or something, so it broadcasts to all worlds? And move this to cWorld?
|
||||
void cServer::Broadcast( const cPacket & a_Packet, cClientHandle* a_Exclude /* = 0 */ )
|
||||
{
|
||||
@@ -255,6 +287,10 @@ void cServer::Broadcast( const cPacket & a_Packet, cClientHandle* a_Exclude /* =
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cServer::StartListenClient()
|
||||
{
|
||||
cSocket SClient = m_pState->SListenClient.Accept();
|
||||
@@ -272,6 +308,10 @@ void cServer::StartListenClient()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cServer::Tick(float a_Dt)
|
||||
{
|
||||
//LOG("1. Tick %0.2f", a_Dt);
|
||||
@@ -318,6 +358,10 @@ bool cServer::Tick(float a_Dt)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void ServerTickThread( void * a_Param )
|
||||
{
|
||||
LOG("ServerTickThread");
|
||||
@@ -394,14 +438,18 @@ bool cServer::Command( cClientHandle & a_Client, const char* a_Cmd )
|
||||
|
||||
if (split[0].compare("/coords") == 0)
|
||||
{
|
||||
char c_Str[128];
|
||||
sprintf_s( c_Str, 128, "[X:%0.2f] [Y:%0.2f] [Z:%0.2f]", a_Client.GetPlayer()->GetPosX(), a_Client.GetPlayer()->GetPosY(), a_Client.GetPlayer()->GetPosZ() );
|
||||
a_Client.Send( cPacket_Chat( cChatColor::Green + c_Str ) );
|
||||
AString Pos;
|
||||
Printf(Pos, "[X:%0.2f] [Y:%0.2f] [Z:%0.2f]", a_Client.GetPlayer()->GetPosX(), a_Client.GetPlayer()->GetPosY(), a_Client.GetPlayer()->GetPosZ() );
|
||||
a_Client.Send( cPacket_Chat(cChatColor::Green + Pos));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cServer::ServerCommand( const char* a_Cmd )
|
||||
{
|
||||
AString Command( a_Cmd );
|
||||
@@ -472,6 +520,10 @@ void cServer::ServerCommand( const char* a_Cmd )
|
||||
//LOG("You didn't enter anything? (%s)", a_Cmd.c_str() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cServer::SendMessage( const char* a_Message, cPlayer* a_Player /* = 0 */, bool a_bExclude /* = false */ )
|
||||
{
|
||||
cPacket_Chat Chat( a_Message );
|
||||
@@ -485,6 +537,10 @@ void cServer::SendMessage( const char* a_Message, cPlayer* a_Player /* = 0 */, b
|
||||
Broadcast( Chat, (a_Player)?a_Player->GetClientHandle():0 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cServer::Shutdown()
|
||||
{
|
||||
m_bRestarting = true;
|
||||
@@ -503,7 +559,44 @@ void cServer::Shutdown()
|
||||
}
|
||||
|
||||
|
||||
const char* cServer::GetServerID()
|
||||
|
||||
|
||||
|
||||
const AString & cServer::GetServerID(void) const
|
||||
{
|
||||
return m_pState->ServerID.c_str();
|
||||
}
|
||||
return m_pState->ServerID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cServer::KickUser(const AString & iUserName, const AString & iReason)
|
||||
{
|
||||
for (ClientList::iterator itr = m_pState->Clients.begin(); itr != m_pState->Clients.end(); ++itr)
|
||||
{
|
||||
if ((*itr)->GetUsername() == iUserName)
|
||||
{
|
||||
(*itr)->Kick(iReason);
|
||||
}
|
||||
} // for itr - m_pState->Clients[]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cServer::AuthenticateUser(const AString & iUserName)
|
||||
{
|
||||
for (ClientList::iterator itr = m_pState->Clients.begin(); itr != m_pState->Clients.end(); ++itr)
|
||||
{
|
||||
if ((*itr)->GetUsername() == iUserName)
|
||||
{
|
||||
(*itr)->Authenticate();
|
||||
}
|
||||
} // for itr - m_pState->Clients[]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user