Changeset 173

Show
Ignore:
Timestamp:
12/16/09 02:21:21 (9 months ago)
Author:
sausage
Message:

$uptime admin command,
$repub admin command (pub file mutate),
Allow changing of E*F (pub files) locations safely

Location:
eoserv/trunk
Files:
18 modified

Legend:

Unmodified
Added
Removed
  • eoserv/trunk/admin.ini

    r171 r173  
    8888remap = 4 
    8989 
     90# Reloads pub files 
     91# $repub 
     92repub = 4 
     93 
    9094# Forces an arena launch on the current map 
    9195# $arena 
  • eoserv/trunk/src/character.cpp

    r172 r173  
    836836                { 
    837837                        builder.AddChar(npc->index); 
    838                         builder.AddShort(npc->data->id); 
     838                        builder.AddShort(npc->Data()->id); 
    839839                        builder.AddChar(npc->x); 
    840840                        builder.AddChar(npc->y); 
  • eoserv/trunk/src/eoclient.cpp

    r171 r173  
    136136} 
    137137 
     138void EOClient::SendBuilderRaw(PacketBuilder &builder) 
     139{ 
     140        std::string packet(builder); 
     141        this->Send(packet); 
     142} 
     143 
    138144EOClient::~EOClient() 
    139145{ 
  • eoserv/trunk/src/eoclient.hpp

    r171 r173  
    100100 
    101101                void SendBuilder(PacketBuilder &packet); 
     102                void SendBuilderRaw(PacketBuilder &packet); 
    102103 
    103104// Stop doxygen generating a gigantic list of functions 
  • eoserv/trunk/src/eodata.cpp

    r171 r173  
    2121#define SAFE_READ(buf, size, count, fh) if (std::fread(buf, size, count, fh) != static_cast<int>(count)) { std::fclose(fh); safe_fail(__LINE__); } 
    2222 
    23 EIF::EIF(std::string filename) 
    24 { 
     23void EIF::Read(std::string filename) 
     24{ 
     25        this->data.clear(); 
     26 
    2527        std::FILE *fh = std::fopen(filename.c_str(), "rb"); 
    2628        safe_fail_filename = filename.c_str(); 
     
    120122} 
    121123 
    122 ENF::ENF(std::string filename) 
    123 { 
     124void ENF::Read(std::string filename) 
     125{ 
     126        this->data.clear(); 
     127 
    124128        std::FILE *fh = std::fopen(filename.c_str(), "rb"); 
    125129        safe_fail_filename = filename.c_str(); 
     
    204208} 
    205209 
    206 ESF::ESF(std::string filename) 
    207 { 
     210void ESF::Read(std::string filename) 
     211{ 
     212        this->data.clear(); 
     213 
    208214        std::FILE *fh = std::fopen(filename.c_str(), "rb"); 
    209215        safe_fail_filename = filename.c_str(); 
     
    278284} 
    279285 
    280 ECF::ECF(std::string filename) 
    281 { 
     286void ECF::Read(std::string filename) 
     287{ 
     288        this->data.clear(); 
     289 
    282290        std::FILE *fh = std::fopen(filename.c_str(), "rb"); 
    283291        safe_fail_filename = filename.c_str(); 
  • eoserv/trunk/src/eodata.hpp

    r171 r173  
    7373                unsigned char len[2]; 
    7474                PtrVector<EIF_Data> data; 
    75                 EIF(std::string filename); 
     75                EIF(std::string filename) { Read(filename); } 
     76                void Read(std::string filename); 
    7677 
    7778                EIF_Data *Get(unsigned int id); 
     
    166167                unsigned char len[2]; 
    167168                PtrVector<ENF_Data> data; 
    168                 ENF(std::string filename); 
     169                ENF(std::string filename) { Read(filename); } 
     170                void Read(std::string filename); 
    169171 
    170172                ENF_Data *Get(unsigned int id); 
     
    210212                unsigned char len[2]; 
    211213                PtrVector<ESF_Data> data; 
    212                 ESF(std::string filename); 
     214                ESF(std::string filename) { Read(filename); } 
     215                void Read(std::string filename); 
    213216 
    214217                SCRIPT_REGISTER_REF(ESF) 
     
    239242                unsigned char len[2]; 
    240243                PtrVector<ECF_Data> data; 
    241                 ECF(std::string filename); 
     244                ECF(std::string filename) { Read(filename); } 
     245                void Read(std::string filename); 
    242246 
    243247        SCRIPT_REGISTER_REF(ECF) 
  • eoserv/trunk/src/eoserver.cpp

    r171 r173  
    145145                this->sln = 0; 
    146146        } 
     147 
     148        this->start = Timer::GetTime(); 
    147149} 
    148150 
  • eoserv/trunk/src/eoserver.hpp

    r171 r173  
    2929        public: 
    3030                World *world; 
     31                double start; 
    3132 
    3233                EOServer(IPAddress addr, unsigned short port, util::array<std::string, 5> dbinfo, const Config &eoserv_config, const Config &admin_config) : Server(addr, port) 
  • eoserv/trunk/src/handlers/Bank.cpp

    r171 r173  
    2525                        UTIL_PTR_VECTOR_FOREACH(this->player->character->map->npcs, NPC, npc) 
    2626                        { 
    27                                 if (npc->index == id && npc->data->type == ENF::Bank) 
     27                                if (npc->index == id && npc->Data()->type == ENF::Bank) 
    2828                                { 
    2929                                        this->player->character->bank_npc = *npc; 
  • eoserv/trunk/src/handlers/Talk.cpp

    r171 r173  
    279279                                                } 
    280280                                        } 
     281                                } 
     282                                else if (command.length() >= 3 && command.compare(0,3,"rep") == 0 && this->player->character->admin >= static_cast<int>(this->server->world->admin_config["repub"])) 
     283                                { 
     284                                        this->server->world->ReloadPub(); 
    281285                                } 
    282286                                else if (command.length() >= 1 && command.compare(0,1,"r") == 0 && this->player->character->admin >= static_cast<int>(this->server->world->admin_config["rehash"])) 
     
    371375                                        std::exit(0); 
    372376                                } 
    373                                 else if (command.length() == 3 && command.compare(0,3,"obj") == 0 && this->player->character->admin >= static_cast<int>(this->server->world->admin_config["objects"])) 
     377                                else if (command.length() >= 3 && command.compare(0,3,"obj") == 0 && this->player->character->admin >= static_cast<int>(this->server->world->admin_config["objects"])) 
    374378                                { 
    375379                                        std::string buffer = "Objects: "; 
     
    379383                                        this->player->character->ServerMsg(buffer); 
    380384                                } 
     385                                else if (command.length() >= 2 && command.compare(0,2,"up") == 0 && this->player->character->admin >= static_cast<int>(this->server->world->admin_config["uptime"])) 
     386                                { 
     387                                        std::string buffer = "Server started "; 
     388                                        buffer += util::timeago(this->server->start, Timer::GetTime()); 
     389                                        this->player->character->ServerMsg(buffer); 
     390                                } 
    381391                                else if (command.length() >= 1 && command.compare(0,1,"q") == 0 && this->player->character->admin >= static_cast<int>(this->server->world->admin_config["quake"])) 
    382392                                { 
  • eoserv/trunk/src/handlers/Warp.cpp

    r171 r173  
    106106                                { 
    107107                                        reply.AddChar(npc->index); 
    108                                         reply.AddShort(npc->data->id); 
     108                                        reply.AddShort(npc->Data()->id); 
    109109                                        reply.AddChar(npc->x); 
    110110                                        reply.AddChar(npc->y); 
  • eoserv/trunk/src/handlers/Welcome.cpp

    r171 r173  
    296296                                { 
    297297                                        reply.AddChar(npc->index); 
    298                                         reply.AddShort(npc->data->id); 
     298                                        reply.AddShort(npc->Data()->id); 
    299299                                        reply.AddChar(npc->x); 
    300300                                        reply.AddChar(npc->y); 
     
    335335                        { 
    336336                                case FILE_MAP: break; // Map file is pre-loaded in to the variable 
    337                                 case FILE_ITEM: filename = "./data/pub/dat001.eif"; replycode = INIT_FILE_EIF; fileid = 1; break; 
    338                                 case FILE_NPC: filename = "./data/pub/dtn001.enf"; replycode = INIT_FILE_ENF; fileid = 1; break; 
    339                                 case FILE_SPELL: filename = "./data/pub/dsl001.esf"; replycode = INIT_FILE_ESF; fileid = 1; break; 
    340                                 case FILE_CLASS: filename = "./data/pub/dat001.ecf"; replycode = INIT_FILE_ECF; fileid = 1; break; 
     337                                case FILE_ITEM: filename = static_cast<std::string>(this->server->world->config["EIF"]); replycode = INIT_FILE_EIF; fileid = 1; break; 
     338                                case FILE_NPC: filename = static_cast<std::string>(this->server->world->config["ENF"]); replycode = INIT_FILE_ENF; fileid = 1; break; 
     339                                case FILE_SPELL: filename = static_cast<std::string>(this->server->world->config["ESF"]); replycode = INIT_FILE_ESF; fileid = 1; break; 
     340                                case FILE_CLASS: filename = static_cast<std::string>(this->server->world->config["ECF"]); replycode = INIT_FILE_ECF; fileid = 1; break; 
    341341                                default: return false; 
    342342                        } 
  • eoserv/trunk/src/main.cpp

    r172 r173  
    411411                eoserv_config_default(aconfig, "evacuate"      , 2); 
    412412                eoserv_config_default(aconfig, "remap"         , 4); 
     413                eoserv_config_default(aconfig, "repub"         , 4); 
    413414                eoserv_config_default(aconfig, "arena"         , 1); 
    414415                eoserv_config_default(aconfig, "shutdown"      , 4); 
  • eoserv/trunk/src/map.cpp

    r172 r173  
    12751275                UTIL_PTR_VECTOR_FOREACH(this->npcs, NPC, npc) 
    12761276                { 
    1277                         if ((npc->data->type == ENF::Passive || npc->data->type == ENF::Aggressive || from->admin > static_cast<int>(this->world->admin_config["killnpcs"])) 
     1277                        if ((npc->Data()->type == ENF::Passive || npc->Data()->type == ENF::Aggressive || from->admin > static_cast<int>(this->world->admin_config["killnpcs"])) 
    12781278                         && npc->alive && npc->x == target_x && npc->y == target_y) 
    12791279                        { 
     
    12951295 
    12961296                                hit_rate += int(from->accuracy / 2.0); 
    1297                                 hit_rate -= int(double(npc->data->evade) / 2.0 * mobrate); 
     1297                                hit_rate -= int(double(npc->Data()->evade) / 2.0 * mobrate); 
    12981298                                hit_rate = std::min(std::max(hit_rate, 20), 100); 
    12991299 
    13001300                                int origamount = amount; 
    1301                                 amount -= int(double(npc->data->armor) / 3.0 * mobrate); 
     1301                                amount -= int(double(npc->Data()->armor) / 3.0 * mobrate); 
    13021302 
    13031303                                amount = std::max(amount, int(std::ceil(double(origamount) * 0.1))); 
  • eoserv/trunk/src/npc.cpp

    r171 r173  
    4949        this->walk_idle_for = 0; 
    5050 
    51         this->data = map->world->enf->Get(id); 
    52  
    5351        if (spawn_type == 7) 
    5452        { 
     
    160158                } 
    161159        } 
     160} 
     161 
     162ENF_Data *NPC::Data() 
     163{ 
     164        return this->map->world->enf->Get(id); 
    162165} 
    163166 
     
    213216 
    214217        this->alive = true; 
    215         this->hp = this->data->hp; 
     218        this->hp = this->Data()->hp; 
    216219        this->last_act = Timer::GetTime(); 
    217220        this->act_speed = speed_table[this->spawn_type]; 
     
    265268        } 
    266269 
    267         if (this->data->type == ENF::Aggressive && !attacker) 
     270        if (this->Data()->type == ENF::Aggressive && !attacker) 
    268271        { 
    269272                Character *closest = 0; 
     
    413416                builder.AddShort(this->index); 
    414417                builder.AddThree(amount); 
    415                 builder.AddShort(int(double(this->hp) / double(this->data->hp) * 100.0)); 
     418                builder.AddShort(int(double(this->hp) / double(this->Data()->hp) * 100.0)); 
    416419                builder.AddChar(1); // ? 
    417420 
     
    483486                                case 2: 
    484487                                { 
    485                                         int rewarded_hp = util::rand(0, this->data->hp); 
     488                                        int rewarded_hp = util::rand(0, this->Data()->hp); 
    486489                                        int count_hp = 0; 
    487490                                        UTIL_PTR_LIST_FOREACH(this->damagelist, NPC_Opponent, opponent) 
     
    534537                                builder.SetID(PACKET_NPC, PACKET_SPEC); 
    535538 
    536                                 if (this->data->exp != 0) 
     539                                if (this->Data()->exp != 0) 
    537540                                { 
    538541                                        if (findopp) 
     
    544547                                                                if (*character == from) 
    545548                                                                { 
    546                                                                         reward = int(std::ceil(double(this->data->exp) * exprate)); 
     549                                                                        reward = int(std::ceil(double(this->Data()->exp) * exprate)); 
    547550 
    548551                                                                        if (reward > 0) 
     
    570573                                                                if (*character == most_damage) 
    571574                                                                { 
    572                                                                         reward = int(std::ceil(double(this->data->exp) * exprate)); 
     575                                                                        reward = int(std::ceil(double(this->Data()->exp) * exprate)); 
    573576 
    574577                                                                        if (reward > 0) 
     
    594597 
    595598                                                        case 2: 
    596                                                                 reward = int(std::ceil(double(this->data->exp) * exprate * (double(findopp->damage) / double(this->totaldamage)))); 
     599                                                                reward = int(std::ceil(double(this->Data()->exp) * exprate * (double(findopp->damage) / double(this->totaldamage)))); 
    597600 
    598601                                                                if (reward > 0) 
     
    618621 
    619622                                                        case 3: 
    620                                                                 reward = int(std::ceil(double(this->data->exp) * exprate * (double(this->damagelist.size()) / 1.0))); 
     623                                                                reward = int(std::ceil(double(this->Data()->exp) * exprate * (double(this->damagelist.size()) / 1.0))); 
    621624 
    622625                                                                if (reward > 0) 
     
    713716        double mobrate = this->map->world->config["MobRate"]; 
    714717 
    715         int amount = util::rand(this->data->mindam, this->data->maxdam + static_cast<int>(this->map->world->config["NPCAdjustMaxDam"])); 
     718        int amount = util::rand(this->Data()->mindam, this->Data()->maxdam + static_cast<int>(this->map->world->config["NPCAdjustMaxDam"])); 
    716719 
    717720        int hit_rate = 120; 
     
    727730        } 
    728731 
    729         hit_rate += int(double(this->data->accuracy) / 2.0 * mobrate); 
     732        hit_rate += int(double(this->Data()->accuracy) / 2.0 * mobrate); 
    730733        hit_rate -= int(double(target->evade) / 2.0); 
    731734        hit_rate = std::min(std::max(hit_rate, 20), 100); 
  • eoserv/trunk/src/npc.hpp

    r171 r173  
    6969                bool temporary; 
    7070                short id; 
    71                 ENF_Data *data; 
    7271                unsigned char x, y; 
    7372                Direction direction; 
     
    9695                NPC(Map *map, short id, unsigned char x, unsigned char y, unsigned char spawn_type, short spawn_time, unsigned char index, bool temporary = false); 
    9796 
     97                ENF_Data *Data(); 
     98 
    9899                bool SpawnReady(); 
    99100 
  • eoserv/trunk/src/world.cpp

    r171 r173  
    377377} 
    378378 
     379void World::ReloadPub() 
     380{ 
     381        this->eif->Read(this->config["EIF"]); 
     382        this->enf->Read(this->config["ENF"]); 
     383        this->esf->Read(this->config["ESF"]); 
     384        this->ecf->Read(this->config["ECF"]); 
     385 
     386        std::string filename; 
     387        std::FILE *fh; 
     388        InitReply replycode; 
     389 
     390        for (int i = 0; i < 4; ++i) 
     391        { 
     392                std::string content; 
     393 
     394                switch (i) 
     395                { 
     396                        case 0: filename = static_cast<std::string>(this->config["EIF"]); replycode = INIT_FILE_EIF; break; 
     397                        case 1: filename = static_cast<std::string>(this->config["ENF"]); replycode = INIT_FILE_ENF; break; 
     398                        case 2: filename = static_cast<std::string>(this->config["ESF"]); replycode = INIT_FILE_ESF; break; 
     399                        case 3: filename = static_cast<std::string>(this->config["ECF"]); replycode = INIT_FILE_ECF; break; 
     400                } 
     401 
     402                fh = std::fopen(filename.c_str(), "rb"); 
     403 
     404                if (!fh) 
     405                { 
     406                        Console::Err("Could not load file: %s", filename.c_str()); 
     407                        std::exit(1); 
     408                } 
     409 
     410                do { 
     411                        char buf[4096]; 
     412                        int len = std::fread(buf, sizeof(char), 4096, fh); 
     413                        content.append(buf, len); 
     414                } while (!std::feof(fh)); 
     415 
     416                std::fclose(fh); 
     417 
     418                PacketBuilder builder(0); 
     419                builder.AddChar(replycode); 
     420                builder.AddChar(1); // fileid 
     421                builder.AddString(content); 
     422 
     423                UTIL_PTR_VECTOR_FOREACH(this->characters, Character, character) 
     424                { 
     425                        character->player->client->SendBuilderRaw(builder); 
     426                } 
     427        } 
     428 
     429        UTIL_PTR_VECTOR_FOREACH(this->characters, Character, character) 
     430        { 
     431                character->Warp(character->mapid, character->x, character->y); 
     432        } 
     433} 
     434 
    379435Character *World::GetCharacter(std::string name) 
    380436{ 
  • eoserv/trunk/src/world.hpp

    r171 r173  
    100100                void Reboot(int seconds, std::string reason); 
    101101 
     102                void ReloadPub(); 
     103 
    102104                void Kick(Character *from, Character *victim, bool announce = true); 
    103105                void Jail(Character *from, Character *victim, bool announce = true);