about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authoroy <Tom_Adams@web.de>2011-03-15 11:23:49 +0100
committeroy <Tom_Adams@web.de>2011-03-15 11:23:49 +0100
commit30d9c9f4d9e46fec403f3fa810898017a18e93b6 (patch)
tree722a14c6fb470c65e21a1ec8daab0c1391c03d38 /src
parent27e5a6af0d09192e1a865332f35bde4a0ac180dd (diff)
downloadzcatch-30d9c9f4d9e46fec403f3fa810898017a18e93b6.tar.gz
zcatch-30d9c9f4d9e46fec403f3fa810898017a18e93b6.zip
made network support clan name and country code for players
Diffstat (limited to 'src')
-rw-r--r--src/engine/server.h4
-rw-r--r--src/engine/server/server.cpp52
-rw-r--r--src/engine/server/server.h7
-rw-r--r--src/engine/shared/config_variables.h5
-rw-r--r--src/engine/shared/protocol.h5
-rw-r--r--src/game/client/gameclient.cpp12
-rw-r--r--src/game/client/gameclient.h4
-rw-r--r--src/game/server/gamecontext.cpp4
-rw-r--r--src/game/server/player.cpp4
9 files changed, 85 insertions, 12 deletions
diff --git a/src/engine/server.h b/src/engine/server.h
index 4f37e8fe..edc60767 100644
--- a/src/engine/server.h
+++ b/src/engine/server.h
@@ -26,6 +26,8 @@ public:
 	int TickSpeed() const { return m_TickSpeed; }
 
 	virtual const char *ClientName(int ClientID) = 0;
+	virtual const char *ClientClan(int ClientID) = 0;
+	virtual int ClientCountry(int ClientID) = 0;
 	virtual bool ClientIngame(int ClientID) = 0;
 	virtual int GetClientInfo(int ClientID, CClientInfo *pInfo) = 0;
 	virtual void GetClientIP(int ClientID, char *pIPString, int Size) = 0;
@@ -43,6 +45,8 @@ public:
 	}
 	
 	virtual void SetClientName(int ClientID, char const *pName) = 0;
+	virtual void SetClientClan(int ClientID, char const *pClan) = 0;
+	virtual void SetClientCountry(int ClientID, int Country) = 0;
 	virtual void SetClientScore(int ClientID, int Score) = 0;
 	
 	virtual int SnapNewID() = 0;
diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp
index f385a312..fcc141bb 100644
--- a/src/engine/server/server.cpp
+++ b/src/engine/server/server.cpp
@@ -192,6 +192,11 @@ int CServer::TrySetClientName(int ClientID, const char *pName)
 	// trim the name
 	str_copy(aTrimmedName, StrLtrim(pName), sizeof(aTrimmedName));
 	StrRtrim(aTrimmedName);
+
+	// check if new and old name are the same
+	if(str_comp(m_aClients[ClientID].m_aName, aTrimmedName) == 0)
+		return 0;
+
 	char aBuf[256];
 	str_format(aBuf, sizeof(aBuf), "'%s' -> '%s'", pName, aTrimmedName);
 	Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBuf);
@@ -239,6 +244,22 @@ void CServer::SetClientName(int ClientID, const char *pName)
 	}
 }
 
+void CServer::SetClientClan(int ClientID, const char *pClan)
+{
+	if(ClientID < 0 || ClientID >= MAX_CLIENTS || m_aClients[ClientID].m_State < CClient::STATE_READY || !pClan)
+		return;
+		
+	str_copy(m_aClients[ClientID].m_aClan, pClan, MAX_CLAN_LENGTH);
+}
+
+void CServer::SetClientCountry(int ClientID, int Country)
+{
+	if(ClientID < 0 || ClientID >= MAX_CLIENTS || m_aClients[ClientID].m_State < CClient::STATE_READY)
+		return;
+		
+	m_aClients[ClientID].m_Country = Country;
+}
+
 void CServer::SetClientScore(int ClientID, int Score)
 {
 	if(ClientID < 0 || ClientID >= MAX_CLIENTS || m_aClients[ClientID].m_State < CClient::STATE_READY)
@@ -284,6 +305,7 @@ int CServer::Init()
 		m_aClients[i].m_State = CClient::STATE_EMPTY;
 		m_aClients[i].m_aName[0] = 0;
 		m_aClients[i].m_aClan[0] = 0;
+		m_aClients[i].m_Country = -1;
 		m_aClients[i].m_Snapshots.Init();
 	}
 
@@ -332,10 +354,32 @@ const char *CServer::ClientName(int ClientID)
 {
 	if(ClientID < 0 || ClientID >= MAX_CLIENTS || m_aClients[ClientID].m_State == CServer::CClient::STATE_EMPTY)
 		return "(invalid client)";
-	else if(m_aClients[ClientID].m_State < CServer::CClient::STATE_READY)
+	if(m_aClients[ClientID].m_State == CServer::CClient::STATE_INGAME)
+		return m_aClients[ClientID].m_aName;
+	else
 		return "(connecting client)";
-	return m_aClients[ClientID].m_aName;
-}	
+	
+}
+
+const char *CServer::ClientClan(int ClientID)
+{
+	if(ClientID < 0 || ClientID >= MAX_CLIENTS || m_aClients[ClientID].m_State == CServer::CClient::STATE_EMPTY)
+		return "";
+	if(m_aClients[ClientID].m_State == CServer::CClient::STATE_INGAME)
+		return m_aClients[ClientID].m_aClan;
+	else
+		return "";
+}
+
+int CServer::ClientCountry(int ClientID)
+{
+	if(ClientID < 0 || ClientID >= MAX_CLIENTS || m_aClients[ClientID].m_State == CServer::CClient::STATE_EMPTY)
+		return -1;
+	if(m_aClients[ClientID].m_State == CServer::CClient::STATE_INGAME)
+		return m_aClients[ClientID].m_Country;
+	else
+		return -1;
+}
 
 bool CServer::ClientIngame(int ClientID)
 {
@@ -531,6 +575,7 @@ int CServer::NewClientCallback(int ClientID, void *pUser)
 	pThis->m_aClients[ClientID].m_State = CClient::STATE_AUTH;
 	pThis->m_aClients[ClientID].m_aName[0] = 0;
 	pThis->m_aClients[ClientID].m_aClan[0] = 0;
+	pThis->m_aClients[ClientID].m_Country = -1;
 	pThis->m_aClients[ClientID].m_Authed = 0;
 	pThis->m_aClients[ClientID].m_AuthTries = 0;
 	pThis->m_aClients[ClientID].Reset();
@@ -557,6 +602,7 @@ int CServer::DelClientCallback(int ClientID, const char *pReason, void *pUser)
 	pThis->m_aClients[ClientID].m_State = CClient::STATE_EMPTY;
 	pThis->m_aClients[ClientID].m_aName[0] = 0;
 	pThis->m_aClients[ClientID].m_aClan[0] = 0;
+	pThis->m_aClients[ClientID].m_Country = -1;
 	pThis->m_aClients[ClientID].m_Authed = 0;
 	pThis->m_aClients[ClientID].m_AuthTries = 0;
 	pThis->m_aClients[ClientID].m_Snapshots.PurgeAll();
diff --git a/src/engine/server/server.h b/src/engine/server/server.h
index 77cfc484..848b485a 100644
--- a/src/engine/server/server.h
+++ b/src/engine/server/server.h
@@ -87,7 +87,8 @@ public:
 		int m_CurrentInput;
 		
 		char m_aName[MAX_NAME_LENGTH];
-		char m_aClan[MAX_CLANNAME_LENGTH];
+		char m_aClan[MAX_CLAN_LENGTH];
+		int m_Country;
 		int m_Score;
 		int m_Authed;
 		int m_AuthTries;
@@ -126,6 +127,8 @@ public:
 	int TrySetClientName(int ClientID, const char *pName);
 
 	virtual void SetClientName(int ClientID, const char *pName);
+	virtual void SetClientClan(int ClientID, char const *pClan);
+	virtual void SetClientCountry(int ClientID, int Country);
 	virtual void SetClientScore(int ClientID, int Score);
 
 	void Kick(int ClientID, const char *pReason);
@@ -140,6 +143,8 @@ public:
 	int GetClientInfo(int ClientID, CClientInfo *pInfo);
 	void GetClientIP(int ClientID, char *pIPString, int Size);
 	const char *ClientName(int ClientID);
+	const char *ClientClan(int ClientID);
+	int ClientCountry(int ClientID);
 	bool ClientIngame(int ClientID);
 
 	int *LatestInput(int ClientID, int *size);
diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h
index afb24e54..c495461e 100644
--- a/src/engine/shared/config_variables.h
+++ b/src/engine/shared/config_variables.h
@@ -8,8 +8,9 @@
 #include "././game/variables.h"
 
 
-MACRO_CONFIG_STR(PlayerName, player_name, 24, "nameless tee", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Name of the player")
-MACRO_CONFIG_STR(ClanName, clan_name, 32, "", CFGFLAG_SAVE|CFGFLAG_CLIENT, "(not used)")
+MACRO_CONFIG_STR(PlayerName, player_name, 16, "nameless tee", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Name of the player")
+MACRO_CONFIG_STR(PlayerClan, player_clan, 12, "", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Clan of the player")
+MACRO_CONFIG_INT(PlayerCountry, player_country, -1, -1, 1000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Country of the player")
 MACRO_CONFIG_STR(Password, password, 32, "", CFGFLAG_CLIENT|CFGFLAG_SERVER, "Password to the server")
 MACRO_CONFIG_STR(Logfile, logfile, 128, "", CFGFLAG_SAVE|CFGFLAG_CLIENT|CFGFLAG_SERVER, "Filename to log all output to")
 MACRO_CONFIG_INT(ConsoleOutputLevel, console_output_level, 0, 0, 2, CFGFLAG_CLIENT|CFGFLAG_SERVER, "Adjusts the amount of information in the console")
diff --git a/src/engine/shared/protocol.h b/src/engine/shared/protocol.h
index 296294d9..859f4941 100644
--- a/src/engine/shared/protocol.h
+++ b/src/engine/shared/protocol.h
@@ -79,9 +79,8 @@ enum
 	MAX_INPUT_SIZE=128,
 	MAX_SNAPSHOT_PACKSIZE=900,
 
-	MAX_CLANNAME_LENGTH=32,
-	MAX_NAME_LENGTH=24,
-	
+	MAX_NAME_LENGTH=16,
+	MAX_CLAN_LENGTH=12,
 
 	// message packing
 	MSGFLAG_VITAL=1,
diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp
index 0e2e8056..b6e89a7b 100644
--- a/src/game/client/gameclient.cpp
+++ b/src/game/client/gameclient.cpp
@@ -324,6 +324,8 @@ void CGameClient::OnReset()
 	for(int i = 0; i < MAX_CLIENTS; i++)
 	{
 		m_aClients[i].m_aName[0] = 0;
+		m_aClients[i].m_aClan[0] = 0;
+		m_aClients[i].m_Country = -1;
 		m_aClients[i].m_SkinID = 0;
 		m_aClients[i].m_Team = 0;
 		m_aClients[i].m_Angle = 0;
@@ -442,6 +444,8 @@ void CGameClient::OnRender()
 	{
 		// resend if client info differs
 		if(str_comp(g_Config.m_PlayerName, m_aClients[m_Snap.m_LocalClientID].m_aName) ||
+			str_comp(g_Config.m_PlayerClan, m_aClients[m_Snap.m_LocalClientID].m_aClan) ||
+			g_Config.m_PlayerCountry != m_aClients[m_Snap.m_LocalClientID].m_Country ||
 			str_comp(g_Config.m_PlayerSkin, m_aClients[m_Snap.m_LocalClientID].m_aSkinName) ||
 			(m_Snap.m_pGameInfoObj && !(m_Snap.m_pGameInfoObj->m_GameFlags&GAMEFLAG_TEAMS) &&	// no teamgame?
 			(g_Config.m_PlayerUseCustomColor != m_aClients[m_Snap.m_LocalClientID].m_UseCustomColor ||
@@ -685,7 +689,9 @@ void CGameClient::OnNewSnapshot()
 			{
 				const CNetObj_ClientInfo *pInfo = (const CNetObj_ClientInfo *)pData;
 				int ClientID = Item.m_ID;
-				IntsToStr(&pInfo->m_Name0, 6, m_aClients[ClientID].m_aName);
+				IntsToStr(&pInfo->m_Name0, 4, m_aClients[ClientID].m_aName);
+				IntsToStr(&pInfo->m_Clan0, 3, m_aClients[ClientID].m_aClan);
+				m_aClients[ClientID].m_Country = pInfo->m_Country;
 				IntsToStr(&pInfo->m_Skin0, 6, m_aClients[ClientID].m_aSkinName);
 				
 				m_aClients[ClientID].m_UseCustomColor = pInfo->m_UseCustomColor;
@@ -1005,6 +1011,8 @@ void CGameClient::SendInfo(bool Start)
 	{
 		CNetMsg_Cl_StartInfo Msg;
 		Msg.m_pName = g_Config.m_PlayerName;
+		Msg.m_pClan = g_Config.m_PlayerClan;
+		Msg.m_Country = g_Config.m_PlayerCountry;
 		Msg.m_pSkin = g_Config.m_PlayerSkin;
 		Msg.m_UseCustomColor = g_Config.m_PlayerUseCustomColor;
 		Msg.m_ColorBody = g_Config.m_PlayerColorBody;
@@ -1015,6 +1023,8 @@ void CGameClient::SendInfo(bool Start)
 	{
 		CNetMsg_Cl_ChangeInfo Msg;
 		Msg.m_pName = g_Config.m_PlayerName;
+		Msg.m_pClan = g_Config.m_PlayerClan;
+		Msg.m_Country = g_Config.m_PlayerCountry;
 		Msg.m_pSkin = g_Config.m_PlayerSkin;
 		Msg.m_UseCustomColor = g_Config.m_PlayerUseCustomColor;
 		Msg.m_ColorBody = g_Config.m_PlayerColorBody;
diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h
index 831cae24..a3092514 100644
--- a/src/game/client/gameclient.h
+++ b/src/game/client/gameclient.h
@@ -159,7 +159,9 @@ public:
 		int m_ColorBody;
 		int m_ColorFeet;
 		
-		char m_aName[64];
+		char m_aName[MAX_NAME_LENGTH];
+		char m_aClan[MAX_CLAN_LENGTH];
+		int m_Country;
 		char m_aSkinName[64];
 		int m_SkinID;
 		int m_SkinColor;
diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp
index 8c3dc3e3..348b6735 100644
--- a/src/game/server/gamecontext.cpp
+++ b/src/game/server/gamecontext.cpp
@@ -796,6 +796,8 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
 		
 		// set start infos
 		Server()->SetClientName(ClientID, pMsg->m_pName);
+		Server()->SetClientClan(ClientID, pMsg->m_pClan);
+		Server()->SetClientCountry(ClientID, pMsg->m_Country);
 		str_copy(pPlayer->m_TeeInfos.m_SkinName, pMsg->m_pSkin, sizeof(pPlayer->m_TeeInfos.m_SkinName));
 		pPlayer->m_TeeInfos.m_UseCustomColor = pMsg->m_UseCustomColor;
 		pPlayer->m_TeeInfos.m_ColorBody = pMsg->m_ColorBody;
@@ -840,6 +842,8 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
 			str_format(aChatText, sizeof(aChatText), "'%s' changed name to '%s'", aOldName, Server()->ClientName(ClientID));
 			SendChat(-1, CGameContext::CHAT_ALL, aChatText);
 		}
+		Server()->SetClientClan(ClientID, pMsg->m_pClan);
+		Server()->SetClientCountry(ClientID, pMsg->m_Country);
 		str_copy(pPlayer->m_TeeInfos.m_SkinName, pMsg->m_pSkin, sizeof(pPlayer->m_TeeInfos.m_SkinName));
 		pPlayer->m_TeeInfos.m_UseCustomColor = pMsg->m_UseCustomColor;
 		pPlayer->m_TeeInfos.m_ColorBody = pMsg->m_ColorBody;
diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp
index 82b45011..6c118a19 100644
--- a/src/game/server/player.cpp
+++ b/src/game/server/player.cpp
@@ -107,7 +107,9 @@ void CPlayer::Snap(int SnappingClient)
 	if(!pClientInfo)
 		return;
 
-	StrToInts(&pClientInfo->m_Name0, 6, Server()->ClientName(m_ClientID));
+	StrToInts(&pClientInfo->m_Name0, 4, Server()->ClientName(m_ClientID));
+	StrToInts(&pClientInfo->m_Clan0, 3, Server()->ClientClan(m_ClientID));
+	pClientInfo->m_Country = Server()->ClientCountry(m_ClientID);
 	StrToInts(&pClientInfo->m_Skin0, 6, m_TeeInfos.m_SkinName);
 	pClientInfo->m_UseCustomColor = m_TeeInfos.m_UseCustomColor;
 	pClientInfo->m_ColorBody = m_TeeInfos.m_ColorBody;