summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/Bindings.cpp78
-rw-r--r--source/Bindings.h2
-rw-r--r--source/ClientHandle.cpp14
-rw-r--r--source/Player.cpp22
-rw-r--r--source/Server.cpp46
-rw-r--r--source/Server.h11
-rw-r--r--source/World.cpp2
7 files changed, 42 insertions, 133 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index 46c5f0f07..9490f733e 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 08/11/13 20:59:51.
+** Generated automatically by tolua++-1.0.92 on 08/12/13 08:16:46.
*/
#ifndef __cplusplus
@@ -11435,80 +11435,6 @@ static int tolua_AllToLua_cServer_SetMaxPlayers00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
-/* method: BroadcastChat of class cServer */
-#ifndef TOLUA_DISABLE_tolua_AllToLua_cServer_BroadcastChat00
-static int tolua_AllToLua_cServer_BroadcastChat00(lua_State* tolua_S)
-{
-#ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
- if (
- !tolua_isusertype(tolua_S,1,"cServer",0,&tolua_err) ||
- !tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
- !tolua_isusertype(tolua_S,3,"const cClientHandle",1,&tolua_err) ||
- !tolua_isnoobj(tolua_S,4,&tolua_err)
- )
- goto tolua_lerror;
- else
-#endif
- {
- cServer* self = (cServer*) tolua_tousertype(tolua_S,1,0);
- const AString a_Message = ((const AString) tolua_tocppstring(tolua_S,2,0));
- const cClientHandle* a_Exclude = ((const cClientHandle*) tolua_tousertype(tolua_S,3,NULL));
-#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'BroadcastChat'", NULL);
-#endif
- {
- self->BroadcastChat(a_Message,a_Exclude);
- tolua_pushcppstring(tolua_S,(const char*)a_Message);
- }
- }
- return 1;
-#ifndef TOLUA_RELEASE
- tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'BroadcastChat'.",&tolua_err);
- return 0;
-#endif
-}
-#endif //#ifndef TOLUA_DISABLE
-
-/* method: SendMessage of class cServer */
-#ifndef TOLUA_DISABLE_tolua_AllToLua_cServer_SendMessage00
-static int tolua_AllToLua_cServer_SendMessage00(lua_State* tolua_S)
-{
-#ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
- if (
- !tolua_isusertype(tolua_S,1,"cServer",0,&tolua_err) ||
- !tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
- !tolua_isusertype(tolua_S,3,"cPlayer",1,&tolua_err) ||
- !tolua_isboolean(tolua_S,4,1,&tolua_err) ||
- !tolua_isnoobj(tolua_S,5,&tolua_err)
- )
- goto tolua_lerror;
- else
-#endif
- {
- cServer* self = (cServer*) tolua_tousertype(tolua_S,1,0);
- const AString a_Message = ((const AString) tolua_tocppstring(tolua_S,2,0));
- cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,3,NULL));
- bool a_bExclude = ((bool) tolua_toboolean(tolua_S,4,false));
-#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SendMessage'", NULL);
-#endif
- {
- self->SendMessage(a_Message,a_Player,a_bExclude);
- tolua_pushcppstring(tolua_S,(const char*)a_Message);
- }
- }
- return 1;
-#ifndef TOLUA_RELEASE
- tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'SendMessage'.",&tolua_err);
- return 0;
-#endif
-}
-#endif //#ifndef TOLUA_DISABLE
-
/* method: GetServerID of class cServer */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cServer_GetServerID00
static int tolua_AllToLua_cServer_GetServerID00(lua_State* tolua_S)
@@ -29850,8 +29776,6 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"GetMaxPlayers",tolua_AllToLua_cServer_GetMaxPlayers00);
tolua_function(tolua_S,"GetNumPlayers",tolua_AllToLua_cServer_GetNumPlayers00);
tolua_function(tolua_S,"SetMaxPlayers",tolua_AllToLua_cServer_SetMaxPlayers00);
- tolua_function(tolua_S,"BroadcastChat",tolua_AllToLua_cServer_BroadcastChat00);
- tolua_function(tolua_S,"SendMessage",tolua_AllToLua_cServer_SendMessage00);
tolua_function(tolua_S,"GetServerID",tolua_AllToLua_cServer_GetServerID00);
tolua_endmodule(tolua_S);
tolua_cclass(tolua_S,"cWorld","cWorld","",NULL);
diff --git a/source/Bindings.h b/source/Bindings.h
index 10f874e41..8bc484aa0 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 08/11/13 20:59:52.
+** Generated automatically by tolua++-1.0.92 on 08/12/13 08:16:46.
*/
/* Exported function */
diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp
index 14b052652..54e191281 100644
--- a/source/ClientHandle.cpp
+++ b/source/ClientHandle.cpp
@@ -1355,12 +1355,14 @@ void cClientHandle::Tick(float a_Dt)
m_ShouldCheckDownloaded = false;
}
+ if (m_Player == NULL)
+ {
+ return;
+ }
+
// Send a ping packet:
cTimer t1;
- if (
- (m_Player != NULL) && // Is logged in?
- (m_LastPingTime + cClientHandle::PING_TIME_MS <= t1.GetNowTime())
- )
+ if ((m_LastPingTime + cClientHandle::PING_TIME_MS <= t1.GetNowTime()))
{
m_PingID++;
m_PingStartTime = t1.GetNowTime();
@@ -1369,7 +1371,7 @@ void cClientHandle::Tick(float a_Dt)
}
// Handle block break animation:
- if ((m_Player != NULL) && (m_BlockDigAnimStage > -1))
+ if (m_BlockDigAnimStage > -1)
{
int lastAnimVal = m_BlockDigAnimStage;
m_BlockDigAnimStage += (int)(m_BlockDigAnimSpeed * a_Dt);
@@ -1955,7 +1957,7 @@ void cClientHandle::SendConfirmPosition(void)
if (!cRoot::Get()->GetPluginManager()->CallHookPlayerJoined(*m_Player))
{
// Broadcast that this player has joined the game! Yay~
- cRoot::Get()->GetServer()->BroadcastChat(m_Username + " joined the game!", this);
+ m_Player->GetWorld()->BroadcastChat(m_Username + " joined the game!", this);
}
SendPlayerMoveLook();
diff --git a/source/Player.cpp b/source/Player.cpp
index 03c871736..df7e1d539 100644
--- a/source/Player.cpp
+++ b/source/Player.cpp
@@ -129,6 +129,12 @@ bool cPlayer::Initialize(cWorld * a_World)
{
if (super::Initialize(a_World))
{
+ // Remove the client handle from the server, it will be ticked from this object from now on
+ if (m_ClientHandle != NULL)
+ {
+ cRoot::Get()->GetServer()->ClientMovedToWorld(m_ClientHandle);
+ }
+
GetWorld()->AddPlayer(this);
return true;
}
@@ -175,18 +181,22 @@ void cPlayer::SpawnOn(cClientHandle & a_Client)
void cPlayer::Tick(float a_Dt, cChunk & a_Chunk)
{
- if (!m_ClientHandle->IsPlaying())
+ if (m_ClientHandle != NULL)
{
- // We're not yet in the game, ignore everything
- return;
+ if (!m_ClientHandle->IsPlaying())
+ {
+ // We're not yet in the game, ignore everything
+ return;
+ }
+ m_ClientHandle->Tick(a_Dt);
}
super::Tick(a_Dt, a_Chunk);
- // set player swimming state
- SetSwimState( a_Chunk);
+ // Set player swimming state
+ SetSwimState(a_Chunk);
- // handle air drowning stuff
+ // Handle air drowning stuff
HandleAir();
if (m_bDirtyPosition)
diff --git a/source/Server.cpp b/source/Server.cpp
index 0045d4808..82a4cb9f5 100644
--- a/source/Server.cpp
+++ b/source/Server.cpp
@@ -162,6 +162,16 @@ void cServer::RemoveClient(const cClientHandle * a_Client)
+void cServer::ClientMovedToWorld(const cClientHandle * a_Client)
+{
+ cCSLock Lock(m_CSClients);
+ m_Clients.remove(const_cast<cClientHandle *>(a_Client));
+}
+
+
+
+
+
bool cServer::InitServer(cIniFile & a_SettingsIni)
{
m_Description = a_SettingsIni.GetValue ("Server", "Description", "MCServer! - In C++!").c_str();
@@ -298,23 +308,6 @@ void cServer::OnConnectionAccepted(cSocket & a_Socket)
-void cServer::BroadcastChat(const AString & a_Message, const cClientHandle * a_Exclude)
-{
- cCSLock Lock(m_CSClients);
- for (ClientList::iterator itr = m_Clients.begin(); itr != m_Clients.end(); ++itr)
- {
- if ((*itr == a_Exclude) || !(*itr)->IsLoggedIn())
- {
- continue;
- }
- (*itr)->SendChat(a_Message);
- }
-}
-
-
-
-
-
bool cServer::Tick(float a_Dt)
{
cRoot::Get()->TickCommands();
@@ -452,25 +445,6 @@ void cServer::BindBuiltInConsoleCommands(void)
-void cServer::SendMessage(const AString & a_Message, cPlayer * a_Player /* = NULL */, bool a_bExclude /* = false */ )
-{
- if ((a_Player != NULL) && !a_bExclude)
- {
- cClientHandle * Client = a_Player->GetClientHandle();
- if (Client != NULL)
- {
- Client->SendChat(a_Message);
- }
- return;
- }
-
- BroadcastChat(a_Message, (a_Player != NULL) ? a_Player->GetClientHandle() : NULL);
-}
-
-
-
-
-
void cServer::Shutdown(void)
{
m_ListenThreadIPv4.Stop();
diff --git a/source/Server.h b/source/Server.h
index 176c82a40..fad7fc12a 100644
--- a/source/Server.h
+++ b/source/Server.h
@@ -46,8 +46,6 @@ public: // tolua_export
int GetNumPlayers(void) const { return m_NumPlayers; }
void SetMaxPlayers(int a_MaxPlayers) { m_MaxPlayers = a_MaxPlayers; }
- void BroadcastChat(const AString & a_Message, const cClientHandle * a_Exclude = NULL);
-
// tolua_end
bool Start(void);
@@ -62,8 +60,6 @@ public: // tolua_export
void Shutdown(void);
- void SendMessage(const AString & a_Message, cPlayer * a_Player = NULL, bool a_bExclude = false ); // tolua_export
-
void KickUser(int a_ClientID, const AString & a_Reason);
void AuthenticateUser(int a_ClientID); // Called by cAuthenticator to auth the specified user
@@ -79,6 +75,9 @@ public: // tolua_export
void RemoveClient(const cClientHandle * a_Client); // Removes the clienthandle from m_SocketThreads
+ /// Don't tick a_Client anymore, it will be ticked from its cPlayer instead
+ void ClientMovedToWorld(const cClientHandle * a_Client);
+
CryptoPP::RSA::PrivateKey & GetPrivateKey(void) { return m_PrivateKey; }
CryptoPP::RSA::PublicKey & GetPublicKey (void) { return m_PublicKey; }
@@ -132,8 +131,8 @@ private:
cListenThread m_ListenThreadIPv4;
cListenThread m_ListenThreadIPv6;
- cCriticalSection m_CSClients; // Locks client list
- cClientHandleList m_Clients; // Clients that are connected to the server
+ cCriticalSection m_CSClients; ///< Locks client list
+ cClientHandleList m_Clients; ///< Clients that are connected to the server and not yet assigned to a cWorld
cSocketThreads m_SocketThreads;
diff --git a/source/World.cpp b/source/World.cpp
index 341682a2a..b29bc751f 100644
--- a/source/World.cpp
+++ b/source/World.cpp
@@ -578,7 +578,7 @@ void cWorld::Tick(float a_Dt)
m_WorldAge = (Int64)(m_WorldAgeSecs * 20.0);
m_TimeOfDay = (Int64)(m_TimeOfDaySecs * 20.0);
- // Broadcase time update every 40 ticks (2 seconds)
+ // Broadcast time update every 40 ticks (2 seconds)
if (m_LastTimeUpdate < m_WorldAge - 40)
{
BroadcastTimeUpdate();