fixed #490 (insert the player info in the sv_setinfo message into the snapshot instead)

This commit is contained in:
Magnus Auvinen 2008-10-08 20:47:56 +00:00
parent 1d094181ed
commit 3544db4927
11 changed files with 95 additions and 135 deletions

View file

@ -145,6 +145,21 @@ Objects = [
NetIntAny("latency_flux"),
]),
NetObject("Client_Info", [
# 4*6 = 24 charachters
NetIntAny("name0"), NetIntAny("name1"), NetIntAny("name2"),
NetIntAny("name3"), NetIntAny("name4"), NetIntAny("name5"),
# 4*6 = 24 charachters
NetIntAny("skin0"), NetIntAny("skin1"), NetIntAny("skin2"),
NetIntAny("skin3"), NetIntAny("skin4"), NetIntAny("skin5"),
NetIntRange("use_custom_color", 0, 1),
NetIntAny("color_body"),
NetIntAny("color_feet"),
]),
## Events
NetEvent("Common", [
@ -192,15 +207,6 @@ Messages = [
NetString("message"),
]),
NetMessage("sv_setinfo", [
NetIntRange("cid", 0, 'MAX_CLIENTS-1'),
NetString("name"),
NetString("skin"),
NetBool("use_custom_color"),
NetIntAny("color_body"),
NetIntAny("color_feet"),
]),
NetMessage("sv_killmsg", [
NetIntRange("killer", 0, 'MAX_CLIENTS-1'),
NetIntRange("victim", 0, 'MAX_CLIENTS-1'),

View file

@ -1142,14 +1142,6 @@ static void client_process_packet(NETCHUNK *packet)
swap_endian(&marker, sizeof(int), sizeof(marker)/sizeof(int));
demorec_record_write("TICK", sizeof(marker), &marker);
/* build snap and possibly add some messages */
modc_recordkeyframe();
/*
snapbuild_init(&builder);
mods_snap(-1);
snapshot_size = snapbuild_finish(&builder, data);*/
/* write snapshot */
demorec_record_write("SNAP", snapsize, tmpbuffer3);
}

View file

@ -142,6 +142,4 @@ int modc_snap_input(int *data);
*/
const char *modc_net_version();
void modc_recordkeyframe();
#endif

View file

@ -17,7 +17,6 @@ extern "C" void modc_init() { gameclient.on_init(); }
extern "C" void modc_connected() { gameclient.on_connected(); }
extern "C" void modc_predict() { gameclient.on_predict(); }
extern "C" void modc_newsnapshot() { gameclient.on_snapshot(); }
extern "C" void modc_recordkeyframe() { gameclient.on_recordkeyframe(); }
extern "C" int modc_snap_input(int *data) { return gameclient.on_snapinput(data); }
extern "C" void modc_statechange(int state, int old) { gameclient.on_statechange(state, old); }
extern "C" void modc_render() { gameclient.on_render(); }

View file

@ -424,44 +424,7 @@ void GAMECLIENT::on_message(int msgtype)
for(int i = 0; i < all.num; i++)
all.components[i]->on_message(msgtype, rawmsg);
// handle core messages
if(msgtype == NETMSGTYPE_SV_SETINFO)
{
NETMSG_SV_SETINFO *msg = (NETMSG_SV_SETINFO *)rawmsg;
str_copy(clients[msg->cid].name, msg->name, 64);
str_copy(clients[msg->cid].skin_name, msg->skin, 64);
// make sure that we don't set a special skin on the client
if(clients[msg->cid].skin_name[0] == 'x' || clients[msg->cid].skin_name[1] == '_')
str_copy(clients[msg->cid].skin_name, "default", 64);
clients[msg->cid].color_body = msg->color_body;
clients[msg->cid].color_feet = msg->color_feet;
clients[msg->cid].skin_info.color_body = skins->get_color(msg->color_body);
clients[msg->cid].skin_info.color_feet = skins->get_color(msg->color_feet);
clients[msg->cid].skin_info.size = 64;
// find new skin
clients[msg->cid].skin_id = gameclient.skins->find(clients[msg->cid].skin_name);
if(clients[msg->cid].skin_id < 0)
clients[msg->cid].skin_id = 0;
clients[msg->cid].use_custom_color = msg->use_custom_color;
if(msg->use_custom_color)
clients[msg->cid].skin_info.texture = gameclient.skins->get(clients[msg->cid].skin_id)->color_texture;
else
{
clients[msg->cid].skin_info.texture = gameclient.skins->get(clients[msg->cid].skin_id)->org_texture;
clients[msg->cid].skin_info.color_body = vec4(1,1,1,1);
clients[msg->cid].skin_info.color_feet = vec4(1,1,1,1);
}
clients[msg->cid].update_render_info();
}
else if(msgtype == NETMSGTYPE_SV_READYTOENTER)
if(msgtype == NETMSGTYPE_SV_READYTOENTER)
{
client_entergame();
}
@ -579,7 +542,43 @@ void GAMECLIENT::on_snapshot()
SNAP_ITEM item;
const void *data = snap_get_item(SNAP_CURRENT, i, &item);
if(item.type == NETOBJTYPE_PLAYER_INFO)
if(item.type == NETOBJTYPE_CLIENT_INFO)
{
const NETOBJ_CLIENT_INFO *info = (const NETOBJ_CLIENT_INFO *)data;
int cid = item.id;
ints_to_str(&info->name0, 6, clients[cid].name);
ints_to_str(&info->skin0, 6, clients[cid].skin_name);
clients[cid].use_custom_color = info->use_custom_color;
clients[cid].color_body = info->color_body;
clients[cid].color_feet = info->color_feet;
// prepare the info
if(clients[cid].skin_name[0] == 'x' || clients[cid].skin_name[1] == '_')
str_copy(clients[cid].skin_name, "default", 64);
clients[cid].skin_info.color_body = skins->get_color(clients[cid].color_body);
clients[cid].skin_info.color_feet = skins->get_color(clients[cid].color_feet);
clients[cid].skin_info.size = 64;
// find new skin
clients[cid].skin_id = gameclient.skins->find(clients[cid].skin_name);
if(clients[cid].skin_id < 0)
clients[cid].skin_id = 0;
if(clients[cid].use_custom_color)
clients[cid].skin_info.texture = gameclient.skins->get(clients[cid].skin_id)->color_texture;
else
{
clients[cid].skin_info.texture = gameclient.skins->get(clients[cid].skin_id)->org_texture;
clients[cid].skin_info.color_body = vec4(1,1,1,1);
clients[cid].skin_info.color_feet = vec4(1,1,1,1);
}
clients[cid].update_render_info();
}
else if(item.type == NETOBJTYPE_PLAYER_INFO)
{
const NETOBJ_PLAYER_INFO *info = (const NETOBJ_PLAYER_INFO *)data;
@ -808,25 +807,6 @@ void GAMECLIENT::send_kill(int client_id)
client_send_msg();
}
void GAMECLIENT::on_recordkeyframe()
{
for(int i = 0; i < MAX_CLIENTS; i++)
{
if(!snap.player_infos[i])
continue;
NETMSG_SV_SETINFO msg;
msg.cid = i;
msg.name = clients[i].name;
msg.skin = clients[i].skin_name;
msg.use_custom_color = clients[i].use_custom_color;
msg.color_body = clients[i].color_body;
msg.color_feet = clients[i].color_feet;
msg.pack(MSGFLAG_NOSEND|MSGFLAG_RECORD);
client_send_msg();
}
}
void GAMECLIENT::con_team(void *result, void *user_data)
{
((GAMECLIENT*)user_data)->send_switch_team(console_arg_int(result, 0));

View file

@ -119,7 +119,6 @@ public:
void on_snapshot();
void on_predict();
int on_snapinput(int *data);
void on_recordkeyframe();
// actions
// TODO: move these

View file

@ -53,6 +53,41 @@ inline float get_angle(vec2 dir)
return a;
}
inline void str_to_ints(int *ints, int num, const char *str)
{
int index = 0;
while(num)
{
char buf[4] = {0,0,0,0};
for(int c = 0; c < 4 && str[index]; c++, index++)
buf[c] = str[index];
*ints = (buf[0]<<24)|(buf[1]<<16)|(buf[2]<<8)|buf[3];
ints++;
num--;
}
// null terminate
ints[-1] &= 0xffffff00;
}
inline void ints_to_str(const int *ints, int num, char *str)
{
while(num)
{
str[0] = ((*ints)>>24)&0xff;
str[1] = ((*ints)>>16)&0xff;
str[2] = ((*ints)>>8)&0xff;
str[3] = (*ints)&0xff;
str += 4;
ints++;
num--;
}
// null terminate
str[-1] = 0;
}
inline vec2 calc_pos(vec2 p, vec2 v, float curvature, float speed, float t)
{

View file

@ -170,29 +170,6 @@ void GAMECONTEXT::send_chat(int chatter_cid, int team, const char *text)
}
}
void GAMECONTEXT::send_info(int who, int to_who, bool recordonly)
{
NETMSG_SV_SETINFO msg;
msg.cid = who;
msg.name = server_clientname(who);
msg.skin = players[who]->skin_name;
msg.use_custom_color = players[who]->use_custom_color;
msg.color_body = players[who]->color_body;
msg.color_feet = players[who]->color_feet;
if(recordonly)
{
msg.pack(MSGFLAG_NOSEND);
server_send_msg(to_who);
}
else
{
msg.pack(MSGFLAG_VITAL);
server_send_msg(to_who);
}
}
void GAMECONTEXT::send_emoticon(int cid, int emoticon)
{
NETMSG_SV_EMOTICON msg;
@ -219,8 +196,6 @@ void GAMECONTEXT::send_broadcast(const char *text, int cid)
server_send_msg(cid);
}
//
void GAMECONTEXT::start_vote(const char *desc, const char *command)
{
@ -341,18 +316,6 @@ void GAMECONTEXT::tick()
void GAMECONTEXT::snap(int client_id)
{
// check if we are recording a demo
if(client_id == -1)
{
// we are recording, make sure that we set
// the info for all players all the time
for(int i = 0; i < MAX_CLIENTS; i++)
{
if(game.players[i])
send_info(i, -1, true);
}
}
world.snap(client_id);
controller->snap(client_id);
events.snap(client_id);

View file

@ -77,7 +77,6 @@ public:
void send_emoticon(int cid, int emoticon);
void send_weapon_pickup(int cid, int weapon);
void send_broadcast(const char *text, int cid);
void send_info(int who, int to_who, bool recordonly = false);
};

View file

@ -281,15 +281,6 @@ void mods_message(int msgtype, int client_id)
if(msgtype == NETMSGTYPE_CL_STARTINFO)
{
// a client that connected!
// send all info to this client
for(int i = 0; i < MAX_CLIENTS; i++)
{
if(game.players[i])
game.send_info(i, client_id);
}
// send tuning parameters to client
send_tuning_params(client_id);
@ -306,8 +297,6 @@ void mods_message(int msgtype, int client_id)
m.pack(MSGFLAG_VITAL|MSGFLAG_FLUSH);
server_send_msg(client_id);
}
game.send_info(client_id, -1);
}
else if (msgtype == NETMSGTYPE_CL_EMOTICON)
{

View file

@ -62,6 +62,13 @@ void PLAYER::tick()
void PLAYER::snap(int snaping_client)
{
NETOBJ_CLIENT_INFO *client_info = (NETOBJ_CLIENT_INFO *)snap_new_item(NETOBJTYPE_CLIENT_INFO, client_id, sizeof(NETOBJ_CLIENT_INFO));
str_to_ints(&client_info->name0, 6, server_clientname(client_id));
str_to_ints(&client_info->skin0, 6, skin_name);
client_info->use_custom_color = use_custom_color;
client_info->color_body = color_body;
client_info->color_feet = color_feet;
NETOBJ_PLAYER_INFO *info = (NETOBJ_PLAYER_INFO *)snap_new_item(NETOBJTYPE_PLAYER_INFO, client_id, sizeof(NETOBJ_PLAYER_INFO));
info->latency = latency.min;
@ -151,13 +158,6 @@ void PLAYER::set_team(int new_team)
dbg_msg("game", "team_join player='%d:%s' team=%d", client_id, server_clientname(client_id), team);
game.controller->on_player_info_change(game.players[client_id]);
// send all info to this client
for(int i = 0; i < MAX_CLIENTS; i++)
{
if(game.players[i])
game.send_info(i, -1);
}
}
void PLAYER::try_respawn()