Skip to content

Commit

Permalink
HCache | Item Packages Update
Browse files Browse the repository at this point in the history
  • Loading branch information
shennetsind committed Jul 5, 2013
2 parents 0118a09 + 3fd6437 commit dc85ce0
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 14 deletions.
6 changes: 0 additions & 6 deletions .gitignore
Expand Up @@ -60,13 +60,11 @@

# /src/login/
/src/login/Makefile
/src/login/obj_txt
/src/login/obj_sql

# /src/map/
/src/map/Makefile
/src/map/obj_sql
/src/map/obj_txt
/src/map/pcre.h

# /src/test/
Expand All @@ -87,10 +85,6 @@
/tools/*.ilk
/tools/*.pdb

# /plugins/
/plugins/*.dll
/plugins/*.pdb

# /vcproj-12/
/vcproj-12/map-server
/vcproj-12/char-server
Expand Down
57 changes: 56 additions & 1 deletion src/common/socket.c
Expand Up @@ -221,6 +221,13 @@ int naddr_ = 0; // # of ip addresses
// Larger packets cause a buffer overflow and stack corruption.
static size_t socket_max_client_packet = 24576;

#ifdef SHOW_SERVER_STATS
// Data I/O statistics
static size_t socket_data_i = 0, socket_data_ci = 0, socket_data_qi = 0;
static size_t socket_data_o = 0, socket_data_co = 0, socket_data_qo = 0;
static time_t socket_data_last_tick = 0;
#endif

// initial recv buffer size (this will also be the max. size)
// biggest known packet: S 0153 <len>.w <emblem data>.?B -> 24x24 256 color .bmp (0153 + len.w + 1618/1654/1756 bytes)
#define RFIFO_SIZE (2*1024)
Expand Down Expand Up @@ -357,6 +364,14 @@ int recv_to_fifo(int fd)

session[fd]->rdata_size += len;
session[fd]->rdata_tick = last_tick;
#ifdef SHOW_SERVER_STATS
socket_data_i += len;
socket_data_qi += len;
if (!session[fd]->flag.server)
{
socket_data_ci += len;
}
#endif
return 0;
}

Expand All @@ -376,6 +391,9 @@ int send_from_fifo(int fd)
{//An exception has occured
if( sErrno != S_EWOULDBLOCK ) {
//ShowDebug("send_from_fifo: %s, ending connection #%d\n", error_msg(), fd);
#ifdef SHOW_SERVER_STATS
socket_data_qo -= session[fd]->wdata_size;
#endif
session[fd]->wdata_size = 0; //Clear the send queue as we can't send anymore. [Skotlex]
set_eof(fd);
}
Expand All @@ -390,6 +408,14 @@ int send_from_fifo(int fd)
memmove(session[fd]->wdata, session[fd]->wdata + len, session[fd]->wdata_size - len);

session[fd]->wdata_size -= len;
#ifdef SHOW_SERVER_STATS
socket_data_o += len;
socket_data_qo -= len;
if (!session[fd]->flag.server)
{
socket_data_co += len;
}
#endif
}

return 0;
Expand Down Expand Up @@ -566,16 +592,22 @@ static int create_session(int fd, RecvFunc func_recv, SendFunc func_send, ParseF
session[fd]->func_send = func_send;
session[fd]->func_parse = func_parse;
session[fd]->rdata_tick = last_tick;
session[fd]->session_data = NULL;
return 0;
}

static void delete_session(int fd)
{
if( session_isValid(fd) )
{
#ifdef SHOW_SERVER_STATS
socket_data_qi -= session[fd]->rdata_size - session[fd]->rdata_pos;
socket_data_qo -= session[fd]->wdata_size;
#endif
aFree(session[fd]->rdata);
aFree(session[fd]->wdata);
aFree(session[fd]->session_data);
if( session[fd]->session_data )
aFree(session[fd]->session_data);
aFree(session[fd]);
session[fd] = NULL;
}
Expand Down Expand Up @@ -641,6 +673,9 @@ int RFIFOSKIP(int fd, size_t len)
}

s->rdata_pos = s->rdata_pos + len;
#ifdef SHOW_SERVER_STATS
socket_data_qi -= len;
#endif
return 0;
}

Expand Down Expand Up @@ -694,6 +729,9 @@ int WFIFOSET(int fd, size_t len)

}
s->wdata_size += len;
#ifdef SHOW_SERVER_STATS
socket_data_qo += len;
#endif
//If the interserver has 200% of its normal size full, flush the data.
if( s->flag.server && s->wdata_size >= 2*FIFOSIZE_SERVERLINK )
flush_fifo(fd);
Expand Down Expand Up @@ -820,6 +858,23 @@ int do_sockets(int next)
RFIFOFLUSH(i);
}

#ifdef SHOW_SERVER_STATS
if (last_tick != socket_data_last_tick)
{
char buf[1024];

sprintf(buf, "In: %.03f kB/s (%.03f kB/s, Q: %.03f kB) | Out: %.03f kB/s (%.03f kB/s, Q: %.03f kB) | RAM: %.03f MB", socket_data_i/1024., socket_data_ci/1024., socket_data_qi/1024., socket_data_o/1024., socket_data_co/1024., socket_data_qo/1024., iMalloc->usage()/1024.);
#ifdef _WIN32
SetConsoleTitle(buf);
#else
ShowMessage("\033[s\033[1;1H\033[2K%s\033[u", buf);
#endif
socket_data_last_tick = last_tick;
socket_data_i = socket_data_ci = 0;
socket_data_o = socket_data_co = 0;
}
#endif

return 0;
}

Expand Down
1 change: 1 addition & 0 deletions src/common/socket.h
Expand Up @@ -6,6 +6,7 @@
#define _SOCKET_H_

#include "../common/cbasetypes.h"
#include "../config/core.h"

#ifdef WIN32
#include "../common/winapi.h"
Expand Down
4 changes: 2 additions & 2 deletions src/common/utils.c
Expand Up @@ -292,7 +292,7 @@ bool HCache_check(const char *file) {
struct stat bufa, bufb;
FILE *first, *second;
char s_path[255], dT[1];
size_t rtime;
time_t rtime;

if( !(first = fopen(file,"rb")) )
return false;
Expand All @@ -316,7 +316,7 @@ bool HCache_check(const char *file) {
}

fstat(fileno(first), &bufa);
fstat(fileno(first), &bufa);
fstat(fileno(first), &bufb);

fclose(first);
fclose(second);
Expand Down
3 changes: 2 additions & 1 deletion src/common/utils.h
Expand Up @@ -7,6 +7,7 @@

#include "../common/cbasetypes.h"
#include <stdio.h> // FILE*
#include <time.h>

// generate a hex dump of the first 'length' bytes of 'buffer'
void WriteDump(FILE* fp, const void* buffer, size_t length);
Expand Down Expand Up @@ -37,7 +38,7 @@ struct HCache_interface {
bool (*check) (const char *file);
FILE *(*open) (const char *file, const char *opt);
/* */
size_t recompile_time;
time_t recompile_time;
bool enabled;
};

Expand Down
3 changes: 3 additions & 0 deletions src/config/core.h
Expand Up @@ -61,6 +61,9 @@
/// By enabling it, the system will create an unique id for each new non stackable item created
//#define NSI_UNIQUE_ID

/// Uncomment to enable real-time server stats (in and out data and ram usage). [Ai4rei]
//#define SHOW_SERVER_STATS

/**
* No settings past this point
**/
Expand Down
2 changes: 1 addition & 1 deletion src/map/atcommand.c
Expand Up @@ -407,7 +407,7 @@ ACMD(mapmove)
if (mapindex)
m = iMap->mapindex2mapid(mapindex);

if (!mapindex) { // m < 0 means on different server! [Kevin]
if (!mapindex || m < 0) { // m < 0 means on different server or that map is disabled! [Kevin]
clif->message(fd, msg_txt(1)); // Map not found.
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/map/battle.c
Expand Up @@ -6461,7 +6461,7 @@ static const struct _battle_data {
{ "item_enabled_npc", &battle_config.item_enabled_npc, 1, 0, 1, },
{ "gm_ignore_warpable_area", &battle_config.gm_ignore_warpable_area, 0, 2, 100, },
{ "packet_obfuscation", &battle_config.packet_obfuscation, 1, 0, 3, },
{ "client_accept_chatdori", &battle_config.client_accept_chatdori, 0, 0, 1, },
{ "client_accept_chatdori", &battle_config.client_accept_chatdori, 0, 0, INT_MAX, },
};
#ifndef STATS_OPT_OUT
/**
Expand Down
1 change: 1 addition & 0 deletions src/map/clif.c
Expand Up @@ -13419,6 +13419,7 @@ void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
if (pc->get_group_level(sd) > 0 || sd->bl.id != id)
return;

value = battle_config.client_accept_chatdori;
dstsd = sd;
}
else
Expand Down
6 changes: 4 additions & 2 deletions src/map/script.c
Expand Up @@ -4344,8 +4344,10 @@ BUILDIN(callfunc)
{
const char* name = reference_getname(data);
if( name[0] == '.' ) {
ref = (struct DBMap**)aCalloc(sizeof(struct DBMap*), 1);
ref[0] = (name[1] == '@' ? st->stack->var_function : st->script->script_vars);
if( !ref ) {
ref = (struct DBMap**)aCalloc(sizeof(struct DBMap*), 1);
ref[0] = (name[1] == '@' ? st->stack->var_function : st->script->script_vars);
}
data->ref = ref;
}
}
Expand Down

0 comments on commit dc85ce0

Please sign in to comment.