loads of small fixes everywhere

This commit is contained in:
Magnus Auvinen 2008-03-18 01:30:47 +00:00
parent 511720b0e4
commit 944cd68add
7 changed files with 58 additions and 27 deletions

View file

@ -797,7 +797,7 @@ static void client_process_packet(NETPACKET *packet)
const unsigned char *data = msg_unpack_raw(size);
/* check fior errors */
if(msg_unpack_error() || size <= 0 || total_size <= 0)
if(msg_unpack_error() || size <= 0 || total_size <= 0 || !mapdownload_file)
return;
io_write(mapdownload_file, data, size);
@ -1151,6 +1151,12 @@ static void client_update()
prevtick_start = prev_pred_tick*time_freq()/50;
predintratick = (pred_now - prevtick_start) / (float)(curtick_start-prevtick_start);
if(new_pred_tick < snapshots[SNAP_PREV]->tick-SERVER_TICK_SPEED/10 || new_pred_tick > snapshots[SNAP_PREV]->tick+SERVER_TICK_SPEED)
{
dbg_msg("client", "prediction time reset!");
st_init(&predicted_time, snapshots[SNAP_CURRENT]->tick*time_freq()/50);
}
if(new_pred_tick > current_predtick)
{
last_predintra = predintratick;
@ -1161,8 +1167,6 @@ static void client_update()
client_send_input();
}
if(predintratick < last_predintra)
dbg_msg("client", "prediction time goes backwards, that can't be good");
last_predintra = predintratick;
}

View file

@ -56,6 +56,7 @@ MACRO_CONFIG_STR(sv_rcon_password, 32, "")
MACRO_CONFIG_INT(debug, 0, 0, 1)
MACRO_CONFIG_INT(dbg_stress, 0, 0, 0)
MACRO_CONFIG_INT(dbg_stress_network, 0, 0, 0)
MACRO_CONFIG_INT(dbg_pref, 0, 0, 1)
MACRO_CONFIG_INT(dbg_graphs, 0, 0, 1)
MACRO_CONFIG_INT(dbg_hitch, 0, 0, 0)

View file

@ -25,16 +25,6 @@ const char *engine_savepath(const char *filename, char *buffer, int max)
return buffer;
}
int engine_stress(float probability)
{
if(!config.dbg_stress)
return 0;
if(rand()/(float)RAND_MAX < probability)
return 1;
return 0;
}
void engine_init(const char *appname)
{
dbg_logger_stdout();

View file

@ -5,6 +5,7 @@
#include "e_packer.h"
#include "e_compression.h"
#include "e_engine.h"
#include "e_config.h"
/* useful for debugging */
#if 0
@ -13,7 +14,7 @@
#define packing_error(p) p->error = 1
#endif
int stress_get_int()
static int stress_get_int()
{
static const int nasty[] = {-1, 0, 1, 66000, -66000, (-1<<31), 0x7fffffff};
if(rand()&1)
@ -21,7 +22,7 @@ int stress_get_int()
return nasty[rand()%6];
}
const char *stress_get_string(int *size)
static const char *stress_get_string(int *size)
{
static char noise[1024];
int i;
@ -35,6 +36,17 @@ const char *stress_get_string(int *size)
return noise;
}
static int stress_prob(float probability)
{
if(!config.dbg_stress_network)
return 0;
if(rand()/(float)RAND_MAX < probability)
return 1;
return 0;
}
void packer_reset(PACKER *p)
{
p->error = 0;
@ -47,8 +59,8 @@ void packer_add_int(PACKER *p, int i)
if(p->error)
return;
/*if(engine_stress(0.05f))
i = stress_get_int();*/
if(stress_prob(0.025f))
i = stress_get_int();
/* make sure that we have space enough */
if(p->end - p->current < 6)
@ -65,13 +77,11 @@ void packer_add_string(PACKER *p, const char *str, int limit)
if(p->error)
return;
/* STRESS: do this better */
/*
if(engine_stress(0.1f))
if(stress_prob(0.1f))
{
str = stress_get_string(0);
limit = 0;
}*/
}
/* */
if(limit > 0)

View file

@ -313,6 +313,13 @@ int snapshot_create_delta(SNAPSHOT *from, SNAPSHOT *to, void *dstdata)
return (int)((char*)data-(char*)dstdata);
}
static int range_check(void *end, void *ptr, int size)
{
if((const char *)ptr + size > (const char *)end)
return -1;
return 0;
}
int snapshot_unpack_delta(SNAPSHOT *from, SNAPSHOT *to, void *srcdata, int data_size)
{
SNAPBUILD builder;
@ -371,8 +378,7 @@ int snapshot_unpack_delta(SNAPSHOT *from, SNAPSHOT *to, void *srcdata, int data_
id = *data++;
snapshot_current = type;
if(data+itemsize/4 > end)
return -1;
if(range_check(end, data, itemsize) || itemsize < 0) return -1;
key = (type<<16)|id;
@ -380,6 +386,8 @@ int snapshot_unpack_delta(SNAPSHOT *from, SNAPSHOT *to, void *srcdata, int data_
newdata = snapbuild_get_item_data(&builder, key);
if(!newdata)
newdata = (int *)snapbuild_new_item(&builder, key>>16, key&0xffff, itemsize);
if(range_check(end, newdata, itemsize)) return -1;
fromindex = snapshot_get_item_index(from, key);
if(fromindex != -1)
@ -553,12 +561,12 @@ void *snapbuild_new_item(SNAPBUILD *sb, int type, int id, int size)
{
SNAPSHOT_ITEM *obj = (SNAPSHOT_ITEM *)(sb->data+sb->data_size);
if(engine_stress(0.01f))
/*if(stress_prob(0.01f))
{
size += ((rand()%5) - 2)*4;
if(size < 0)
size = 0;
}
}*/
mem_zero(obj, sizeof(SNAPSHOT_ITEM) + size);
obj->type_and_id = (type<<16)|id;

View file

@ -165,6 +165,10 @@ extern "C" void modc_predict()
local_cid = client_id;
}
}
// we can't predict without our own id
if(local_cid == -1)
return;
// predict
for(int tick = client_tick()+1; tick <= client_predtick(); tick++)

View file

@ -34,6 +34,7 @@ int run(int port, NETADDR4 dest)
while(1)
{
// fetch data
int data_trash = 0;
NETADDR4 from;
int bytes = net_udp4_recv(socket, &from, buffer, 1024*2);
if(bytes <= 0)
@ -46,10 +47,12 @@ int run(int port, NETADDR4 dest)
packet *p = (packet *)mem_alloc(sizeof(packet)+bytes, 1);
if(net_addr4_cmp(&from, &dest) == 0)
p->send_to = src;
{
p->send_to = src; // from the server
}
else
{
src = from;
src = from; // from the client
p->send_to = dest;
}
@ -70,6 +73,17 @@ int run(int port, NETADDR4 dest)
p->data_size = bytes;
p->id = id++;
mem_copy(p->data, buffer, bytes);
if(id > 20 && bytes > 6 && data_trash)
{
p->data[6+(rand()%(bytes-6))] = rand()&255; // modify a byte
if((rand()%10) == 0)
{
p->data_size -= rand()%32;
if(p->data_size < 6)
p->data_size = 6;
}
}
if(debug)
dbg_msg("crapnet", "<< %08d %d.%d.%d.%d:%5d (%d)", p->id, from.ip[0], from.ip[1], from.ip[2], from.ip[3], from.port, p->data_size);