2008-08-27 15:48:50 +00:00
|
|
|
#include <engine/e_client_interface.h>
|
2009-10-27 14:38:53 +00:00
|
|
|
#include <engine/client/graphics.h>
|
2008-08-27 15:48:50 +00:00
|
|
|
#include <engine/e_config.h>
|
|
|
|
#include <game/generated/g_protocol.hpp>
|
|
|
|
#include <game/generated/gc_data.hpp>
|
|
|
|
|
|
|
|
#include <game/client/gameclient.hpp>
|
|
|
|
|
|
|
|
#include "motd.hpp"
|
2008-08-30 08:26:36 +00:00
|
|
|
|
|
|
|
void MOTD::clear()
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
|
|
|
server_motd_time = 0;
|
|
|
|
}
|
|
|
|
|
2008-08-30 08:26:36 +00:00
|
|
|
bool MOTD::is_active()
|
|
|
|
{
|
|
|
|
return time_get() < server_motd_time;
|
|
|
|
}
|
|
|
|
|
2009-06-15 09:46:25 +00:00
|
|
|
void MOTD::on_statechange(int new_state, int old_state)
|
|
|
|
{
|
|
|
|
if(old_state == CLIENTSTATE_ONLINE || old_state == CLIENTSTATE_OFFLINE)
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2008-08-27 15:48:50 +00:00
|
|
|
void MOTD::on_render()
|
|
|
|
{
|
2008-08-30 08:26:36 +00:00
|
|
|
if(!is_active())
|
|
|
|
return;
|
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
float width = 400*3.0f*Graphics()->ScreenAspect();
|
2008-08-27 15:48:50 +00:00
|
|
|
float height = 400*3.0f;
|
2008-08-30 08:26:36 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
Graphics()->MapScreen(0, 0, width, height);
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2008-08-30 08:26:36 +00:00
|
|
|
float h = 800.0f;
|
|
|
|
float w = 650.0f;
|
|
|
|
float x = width/2 - w/2;
|
|
|
|
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);
|
|
|
|
RenderTools()->draw_round_rect(x, y, w, h, 40.0f);
|
|
|
|
Graphics()->QuadsEnd();
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2008-08-30 08:26:36 +00:00
|
|
|
gfx_text(0, x+40.0f, y+40.0f, 32.0f, server_motd, (int)(w-80.0f));
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MOTD::on_message(int msgtype, void *rawmsg)
|
|
|
|
{
|
|
|
|
if(msgtype == NETMSGTYPE_SV_MOTD)
|
|
|
|
{
|
|
|
|
NETMSG_SV_MOTD *msg = (NETMSG_SV_MOTD *)rawmsg;
|
|
|
|
|
|
|
|
// process escaping
|
|
|
|
str_copy(server_motd, msg->message, sizeof(server_motd));
|
|
|
|
for(int i = 0; server_motd[i]; i++)
|
|
|
|
{
|
|
|
|
if(server_motd[i] == '\\')
|
|
|
|
{
|
|
|
|
if(server_motd[i+1] == 'n')
|
|
|
|
{
|
|
|
|
server_motd[i] = ' ';
|
|
|
|
server_motd[i+1] = '\n';
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(server_motd[0] && config.cl_motd_time)
|
|
|
|
server_motd_time = time_get()+time_freq()*config.cl_motd_time;
|
|
|
|
else
|
|
|
|
server_motd_time = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MOTD::on_input(INPUT_EVENT e)
|
|
|
|
{
|
2008-10-23 16:18:33 +00:00
|
|
|
if(is_active() && e.flags&INPFLAG_PRESS && e.key == KEY_ESCAPE)
|
2008-08-30 08:26:36 +00:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
return true;
|
|
|
|
}
|
2008-08-27 15:48:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|