Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #19

Merged
merged 9 commits into from
Apr 24, 2019
110 changes: 98 additions & 12 deletions src/game/server/gamecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ void CGameContext::CreateSound(vec2 Pos, int Sound, int64 Mask)

void CGameContext::SendCommand(int ChatterClientID, const std::string& command)
{
if(m_apPlayers[ChatterClientID]->m_LastCommand && m_apPlayers[ChatterClientID]->m_LastCommand+Server()->TickSpeed()*0.5 > Server()->Tick())
return;
m_apPlayers[ChatterClientID]->m_LastCommand = Server()->Tick();

std::vector<std::string> messageList;
if(command == "cmdlist")
{
Expand Down Expand Up @@ -351,13 +355,15 @@ void CGameContext::SetKillerTeam(int ClientID, int Killer, bool silent)
SendSkinChange(ClientID, -1);
if(!silent) {
char aBuf[128];
char colorbuf[5];
TeamHandler::getInstance().HSLtoRGBString(TeamID, colorbuf);
if(ClientID == TeamID)
{
str_format(aBuf, sizeof(aBuf), "You are back in your team");
str_format(aBuf, sizeof(aBuf), "%s■■■^999 You are back in your team %s■■■", colorbuf, colorbuf);
}
else
{
str_format(aBuf, sizeof(aBuf), "You are now in Team '%s'", Server()->ClientName(TeamID));
str_format(aBuf, sizeof(aBuf), "%s■■■^999 You are now in Team '%s' %s■■■" , colorbuf, Server()->ClientName(TeamID), colorbuf);
}

SendBroadcast(aBuf, ClientID);
Expand Down Expand Up @@ -395,15 +401,78 @@ void CGameContext::ResetSkin(int ClientID)

void CGameContext::SendSkinChange(int ClientID, int TargetID)
{
CNetMsg_Sv_SkinChange Msg;
Msg.m_ClientID = ClientID;
for(int p = 0; p < NUM_SKINPARTS; p++)
{
Msg.m_apSkinPartNames[p] = m_apPlayers[ClientID]->m_TeeInfos.m_aaSkinPartNames[p];
Msg.m_aUseCustomColors[p] = m_apPlayers[ClientID]->m_TeeInfos.m_aUseCustomColors[p];
Msg.m_aSkinPartColors[p] = m_apPlayers[ClientID]->m_TeeInfos.m_aSkinPartColors[p];
}
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL|MSGFLAG_NORECORD, TargetID);
if(TargetID == -1)
{
for(int i = 0; i < MAX_PLAYERS; ++i)
{
if(m_apPlayers[i] && !m_apPlayers[i]->IsDummy())
SendSkinChange(ClientID, i);
}
}
else if(Server()->GetClientVersion(TargetID) >= MIN_SKINCHANGE_CLIENTVERSION)//Send normal message
{
CNetMsg_Sv_SkinChange Msg;
Msg.m_ClientID = ClientID;
for(int p = 0; p < NUM_SKINPARTS; p++)
{
Msg.m_apSkinPartNames[p] = m_apPlayers[ClientID]->m_TeeInfos.m_aaSkinPartNames[p];
Msg.m_aUseCustomColors[p] = m_apPlayers[ClientID]->m_TeeInfos.m_aUseCustomColors[p];
Msg.m_aSkinPartColors[p] = m_apPlayers[ClientID]->m_TeeInfos.m_aSkinPartColors[p];
}
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL|MSGFLAG_NORECORD, TargetID);
}
else//Old Client use old tricks
{
//You can't change skin of the player to himself :/
if(!m_apPlayers[TargetID] || TargetID == ClientID)
return;

//Info Message
CNetMsg_Sv_ClientInfo ClientInfoMsg;
ClientInfoMsg.m_ClientID = ClientID;
ClientInfoMsg.m_Local = 0;
ClientInfoMsg.m_Team = m_apPlayers[ClientID]->GetTeam();
ClientInfoMsg.m_pName = Server()->ClientName(ClientID);
ClientInfoMsg.m_pClan = Server()->ClientClan(ClientID);
ClientInfoMsg.m_Country = Server()->ClientCountry(ClientID);
ClientInfoMsg.m_Silent = true;

//Connection Message
CNetMsg_Sv_ClientInfo NewClientInfoMsg;
NewClientInfoMsg.m_ClientID = ClientID;
NewClientInfoMsg.m_Local = 0;
NewClientInfoMsg.m_Team = m_apPlayers[ClientID]->GetTeam();
NewClientInfoMsg.m_pName = Server()->ClientName(ClientID);
NewClientInfoMsg.m_pClan = Server()->ClientClan(ClientID);
NewClientInfoMsg.m_Country = Server()->ClientCountry(ClientID);
NewClientInfoMsg.m_Silent = true;

//Fill in Skindata
for(int p = 0; p < 6; p++)
{
ClientInfoMsg.m_apSkinPartNames[p] = m_apPlayers[ClientID]->m_TeeInfos.m_aaSkinPartNames[p];
ClientInfoMsg.m_aUseCustomColors[p] = m_apPlayers[ClientID]->m_TeeInfos.m_aUseCustomColors[p];
ClientInfoMsg.m_aSkinPartColors[p] = m_apPlayers[ClientID]->m_TeeInfos.m_aSkinPartColors[p];


NewClientInfoMsg.m_apSkinPartNames[p] = m_apPlayers[ClientID]->m_TeeInfos.m_aaSkinPartNames[p];
NewClientInfoMsg.m_aUseCustomColors[p] = m_apPlayers[ClientID]->m_TeeInfos.m_aUseCustomColors[p];
NewClientInfoMsg.m_aSkinPartColors[p] = m_apPlayers[ClientID]->m_TeeInfos.m_aSkinPartColors[p];
}

//Disconnect Message
CNetMsg_Sv_ClientDrop Msg;
Msg.m_ClientID = ClientID;
Msg.m_pReason = "colorchange";
Msg.m_Silent = true;

/*RECONNECT*/
//Send Disconnect
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL|MSGFLAG_NORECORD, TargetID);
//Send joining of new player
Server()->SendPackMsg(&NewClientInfoMsg, MSGFLAG_VITAL|MSGFLAG_NORECORD, TargetID);
Server()->SendPackMsg(&ClientInfoMsg, MSGFLAG_VITAL|MSGFLAG_NORECORD, TargetID);
}
}

void CGameContext::SendGameMsg(int GameMsgID, int ClientID)
Expand Down Expand Up @@ -819,6 +888,23 @@ void CGameContext::OnClientEnter(int ClientID)
Msg.m_Team = NewClientInfoMsg.m_Team;
Server()->SendPackMsg(&Msg, MSGFLAG_NOSEND, -1);
}

if(Server()->GetClientVersion(ClientID) < MIN_SKINCHANGE_CLIENTVERSION)
{
std::vector<std::string> messageList;
messageList.push_back("Your Client is too old, you may have troubles in this Mod");
messageList.push_back("Reqired 0.7.3 or higher");
CNetMsg_Sv_Chat Msg;
Msg.m_Mode = CHAT_ALL;
Msg.m_ClientID = -1;

Msg.m_TargetID = ClientID;
for(auto it = messageList.begin(); it != messageList.end(); ++it)
{
Msg.m_pMessage = it->c_str();
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID);
}
}
}

void CGameContext::SetStartTeam(int ClientID)
Expand Down Expand Up @@ -1215,7 +1301,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
pPlayer->m_TeeInfosOriginal.m_aSkinPartColors[p] = pMsg->m_aSkinPartColors[p];
}
ApplyStartColors(ClientID, pPlayer->m_TeeInfosOriginal);//does change feet and body colors of original skin
SendChat(-1, CHAT_ALL, ClientID, "Your skinchange will apply next round");
SendChat(ClientID, CHAT_ALL, ClientID, "Your skinchange will apply next round");
// update all clients//don't update, the update will apply next round
/*for(int i = 0; i < MAX_CLIENTS; ++i)
{
Expand Down
9 changes: 6 additions & 3 deletions src/game/server/gamecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,11 @@ void IGameController::OnReset()
GameServer()->m_apPlayers[i]->m_RespawnDisabled = false;
GameServer()->m_apPlayers[i]->Respawn();
GameServer()->m_apPlayers[i]->m_RespawnTick = Server()->Tick()+Server()->TickSpeed()/2;
if(m_RoundCount == 0)
/*if(m_RoundCount == 0)
{
GameServer()->m_apPlayers[i]->m_Score = 0;
GameServer()->m_apPlayers[i]->m_ScoreStartTick = Server()->Tick();
}
}*/
GameServer()->m_apPlayers[i]->m_IsReadyToPlay = true;
GameServer()->ResetSkin(i);
}
Expand Down Expand Up @@ -644,7 +644,10 @@ void IGameController::SetGameState(EGameState GameState, int Timer)
GameServer()->m_World.m_Paused = true;
if(GameServer()->m_apPlayers[m_TopTeam]) {
char aBuf[256];
str_format(aBuf, sizeof(aBuf), "Team '%s' of player '%s' won the round!", TeamHandler::getInstance().GetTeamName(m_TopTeam), Server()->ClientName(m_TopTeam));
GameServer()->m_apPlayers[m_TopTeam]->m_Score+=g_Config.m_SvWinBonus;
char colorbuf[5];
TeamHandler::getInstance().HSLtoRGBString(m_TopTeam, colorbuf);
str_format(aBuf, sizeof(aBuf), "%s■■■^999 Team '%s' of player '%s' won the round! %s■■■", colorbuf, TeamHandler::getInstance().GetTeamName(m_TopTeam), Server()->ClientName(m_TopTeam), colorbuf);

GameServer()->SendBroadcast(aBuf, -1);
}
Expand Down
1 change: 1 addition & 0 deletions src/game/server/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class CPlayer
int m_LastEmote;
int m_LastKill;
int m_LastKillRequest;//prevet server spaming
int m_LastCommand;
int m_LastReadyChange;

// TODO: clean this up
Expand Down
18 changes: 18 additions & 0 deletions src/game/server/teamhandler.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "teamhandler.h"
#include <base/color.h>

int TeamHandler::GetNewTeamColor(int ClientID)
{
Expand Down Expand Up @@ -119,3 +120,20 @@ int TeamHandler::HSLtoInt(int H, int S, int L)
color = (color&0x00FFFFFF) | (255 << 24);
return color;
}

//This is a fun method blargh
void TeamHandler::HSLtoRGBString(int ClientID, char* buf)
{
int HSL = GetNewBodyColor(ClientID);
int h = (HSL >> 16)&(0x000000FF);
int s = (HSL >> 8)&(0x000000FF);
int l = HSL&(0x000000FF);
vec3 hsl = vec3(h/255.0f, s/255.0f, l/255.0f);
vec3 rgb = HslToRgb(hsl);
buf[0] = '^';
for(int i = 0; i < 3; ++i)
buf[1+i] = '0'+(int)(rgb[i]*10);
buf[4] = 0;
}


1 change: 1 addition & 0 deletions src/game/server/teamhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class TeamHandler
int GetNewBodyColor(int ClientID);
int GetNewFeetColor(int ClientID);
const char* GetTeamName(int ClientID);
void HSLtoRGBString(int ClientID, char* buf);
private:
std::string GetBasicColorName(int ClientID);
TeamHandler(){}
Expand Down
2 changes: 2 additions & 0 deletions src/game/variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ MACRO_CONFIG_INT(SvAllowPickups, sv_start_weapon, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_
MACRO_CONFIG_INT(SvAllowWeaponPickups, sv_start_weapon, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_SERVER, "Spawn weapons")

MACRO_CONFIG_INT(SvSelfkillCooldown, sv_selfkill_cooldown, 15, 3, 9999, CFGFLAG_SAVE|CFGFLAG_SERVER, "Cooldown for selfkill, 3 seconds is the teeworlds minimum!");
MACRO_CONFIG_INT(SvWinBonus, sv_selfkill_cooldown, 5, 0, 9999, CFGFLAG_SAVE|CFGFLAG_SERVER, "Bonus for Winning Team leader");

// debug
#ifdef CONF_DEBUG // this one can crash the server if not used correctly
MACRO_CONFIG_INT(DbgDummies, dbg_dummies, 0, 0, MAX_CLIENTS-1, CFGFLAG_SERVER, "")
Expand Down
2 changes: 1 addition & 1 deletion src/game/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
#define GAME_NETVERSION "0.7 802f1be60a05665f"
#define CLIENT_VERSION 0x0703
static const char GAME_RELEASE_VERSION[8] = "0.7.3";
#define CATCH_VERSION "1.0.2"
#define CATCH_VERSION "1.0.3"
#endif