2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <engine/shared/config.h>
|
|
|
|
#include <engine/graphics.h>
|
|
|
|
#include <engine/textrender.h>
|
|
|
|
#include <engine/keys.h>
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <game/generated/protocol.h>
|
|
|
|
#include <game/generated/client_data.h>
|
|
|
|
#include <game/client/gameclient.h>
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#include "motd.h"
|
2008-08-30 08:26:36 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CMotd::Clear()
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_ServerMotdTime = 0;
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
bool CMotd::IsActive()
|
2008-08-30 08:26:36 +00:00
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
return time_get() < m_ServerMotdTime;
|
2008-08-30 08:26:36 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CMotd::OnStateChange(int NewState, int OldState)
|
2009-06-15 09:46:25 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(OldState == IClient::STATE_ONLINE || OldState == IClient::STATE_OFFLINE)
|
|
|
|
Clear();
|
2009-06-15 09:46:25 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CMotd::OnRender()
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(!IsActive())
|
2008-08-30 08:26:36 +00:00
|
|
|
return;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
float Width = 400*3.0f*Graphics()->ScreenAspect();
|
|
|
|
float Height = 400*3.0f;
|
2008-08-30 08:26:36 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
Graphics()->MapScreen(0, 0, Width, Height);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-30 08:26:36 +00:00
|
|
|
float h = 800.0f;
|
|
|
|
float w = 650.0f;
|
2010-05-29 07:25:38 +00:00
|
|
|
float x = Width/2 - w/2;
|
2008-08-30 08:26:36 +00:00
|
|
|
float y = 150.0f;
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
Graphics()->BlendNormal();
|
|
|
|
Graphics()->TextureSet(-1);
|
|
|
|
Graphics()->QuadsBegin();
|
|
|
|
Graphics()->SetColor(0,0,0,0.5f);
|
2010-05-29 07:25:38 +00:00
|
|
|
RenderTools()->DrawRoundRect(x, y, w, h, 40.0f);
|
2009-10-27 14:38:53 +00:00
|
|
|
Graphics()->QuadsEnd();
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
TextRender()->Text(0, x+40.0f, y+40.0f, 32.0f, m_aServerMotd, (int)(w-80.0f));
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CMotd::OnMessage(int MsgType, void *pRawMsg)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(MsgType == NETMSGTYPE_SV_MOTD)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CNetMsg_Sv_Motd *pMsg = (CNetMsg_Sv_Motd *)pRawMsg;
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2015-07-27 01:57:21 +00:00
|
|
|
char* pLast = m_aServerMotd;
|
2011-04-13 18:37:12 +00:00
|
|
|
// process escaping
|
2010-05-29 07:25:38 +00:00
|
|
|
str_copy(m_aServerMotd, pMsg->m_pMessage, sizeof(m_aServerMotd));
|
|
|
|
for(int i = 0; m_aServerMotd[i]; i++)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_aServerMotd[i] == '\\')
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_aServerMotd[i+1] == 'n')
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2015-07-27 01:57:21 +00:00
|
|
|
m_aServerMotd[i] = '\0';
|
|
|
|
m_pClient->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "motd", pLast, true);
|
2010-05-29 07:25:38 +00:00
|
|
|
m_aServerMotd[i] = ' ';
|
|
|
|
m_aServerMotd[i+1] = '\n';
|
2008-08-27 15:48:50 +00:00
|
|
|
i++;
|
2015-07-27 01:57:21 +00:00
|
|
|
pLast = m_aServerMotd+i+1;
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-01 18:16:34 +00:00
|
|
|
if(*pLast)
|
|
|
|
m_pClient->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "motd", pLast, true);
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_aServerMotd[0] && g_Config.m_ClMotdTime)
|
|
|
|
m_ServerMotdTime = time_get()+time_freq()*g_Config.m_ClMotdTime;
|
2008-08-27 15:48:50 +00:00
|
|
|
else
|
2010-05-29 07:25:38 +00:00
|
|
|
m_ServerMotdTime = 0;
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
bool CMotd::OnInput(IInput::CEvent Event)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(IsActive() && Event.m_Flags&IInput::FLAG_PRESS && Event.m_Key == KEY_ESCAPE)
|
2008-08-30 08:26:36 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
Clear();
|
2008-08-30 08:26:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-08-27 15:48:50 +00:00
|
|
|
return false;
|
|
|
|
}
|