update banner configuration https://github.com/HarpyWar/pvpgn/issues/115
This commit is contained in:
parent
91204db81a
commit
0825dd6c18
10 changed files with 102 additions and 64 deletions
|
@ -9,25 +9,9 @@
|
|||
# The files must be in the files/ directory and no path components should be #
|
||||
# listed here, only the filename portion. #
|
||||
# #
|
||||
# ID uniquely identifies the ad when referring to it from the "next" field #
|
||||
# (must be higher than 0). #
|
||||
# #
|
||||
# The "when" field determines which ad banners should be picked to start a #
|
||||
# sequence. These can be used to make the server avoid picking an "answer" #
|
||||
# banner before its corresponding "question" banner by setting it to "start" #
|
||||
# or "init". The first banner that is chosen when the user logs in is an #
|
||||
# "init" banner. These banners are not reused, so you may want to double #
|
||||
# list them as "start" banners. #
|
||||
# #
|
||||
# The "time" field is the number of seconds that the banner should be #
|
||||
# displayed on the client. If it is zero, the ad will be displayed forever. #
|
||||
# #
|
||||
# The "URL" field is the location that the user will be sent to if (s)he #
|
||||
# clicks on the ad. #
|
||||
# #
|
||||
# The "next" field determines which banner will be displayed next. If it is #
|
||||
# zero, then a start banner may be chosen randomly. #
|
||||
# #
|
||||
# The "client" field determines which banner will be displayed to which #
|
||||
# client. Starting with Warcraft III banners are .mng files which are not #
|
||||
# visible by all clients (and .pcx files dont show on Warcraft III). If this #
|
||||
|
@ -38,36 +22,28 @@
|
|||
# that identified with a specific language tag. A value of "any" means #
|
||||
# this banner will be chosen if no banner is defined for a given language. #
|
||||
#
|
||||
# --file name-- -ID- -when- time ---------------URL--------------- --next-- --client-- --lang--#
|
||||
"ad000001.mng" 1 init 30 "http://pvpgn.berlios.de" 0x000000 "WAR3" "any"
|
||||
"ad000001.mng" 2 start 30 "http://pvpgn.berlios.de" 0x000000 "WAR3" "any"
|
||||
# ---file name--- --------------URL-------------- --client-- --lang--#
|
||||
|
||||
"ad000004.mng" 3 init 30 "http://pvpgn.berlios.de" 0x000000 "WAR3" "any"
|
||||
"ad000004.mng" 4 start 30 "http://pvpgn.berlios.de" 0x000000 "WAR3" "any"
|
||||
# PNG(static) or MNG(animation) used in Warcraft 3
|
||||
# (banners are displayed randomly)
|
||||
|
||||
"ad000001.png" "http://pvpgn.pro" "W3XP" "any"
|
||||
"ad000002.mng" "http://pvpgn.pro" "W3XP" "any"
|
||||
|
||||
"ad000001.mng" 5 init 30 "http://pvpgn.berlios.de" 0x000000 "W3XP" "any"
|
||||
"ad000001.mng" 6 start 30 "http://pvpgn.berlios.de" 0x000000 "W3XP" "any"
|
||||
|
||||
# PCX(static) or SMK(animation) used in Starcraft, Warcraft 2, Diablo 1/2
|
||||
# (banners are displayed in series)
|
||||
|
||||
"ad000004.mng" 7 init 30 "http://pvpgn.berlios.de" 0x000000 "W3XP" "any"
|
||||
"ad000004.mng" 8 start 30 "http://pvpgn.berlios.de" 0x000000 "W3XP" "any"
|
||||
"ad000001.smk" "http://pvpgn.pro" "NULL" "any"
|
||||
|
||||
|
||||
"ad000001.smk" 9 init 30 "http://pvpgn.berlios.de" 0x000000 "NULL" "any"
|
||||
"ad000001.smk" 10 start 30 "http://pvpgn.berlios.de" 0x000000 "NULL" "any"
|
||||
|
||||
# "ad000001.smk" 100 init 30 "http://en.wikipedia.org/wiki/Earth" 0x000000 "NULL" "any"
|
||||
# "ad000001.smk" 101 start 30 "http://en.wikipedia.org/wiki/Earth" 0x00006E "NULL" "any"
|
||||
# "ad000001.smk" 102 init 30 "http://en.wikipedia.org/wiki/Germany" 0x000000 "NULL" "deDE"
|
||||
# "ad000001.smk" 103 start 30 "http://en.wikipedia.org/wiki/Germany" 0x00006E "NULL" "deDE"
|
||||
# "ad000001.smk" 104 init 30 "http://en.wikipedia.org/wiki/USA" 0x000000 "NULL" "enUS"
|
||||
# "ad000001.smk" 105 start 30 "http://en.wikipedia.org/wiki/USA" 0x00006E "NULL" "enUS"
|
||||
# "ad000001.smk" 106 init 30 "http://en.wikipedia.org/wiki/France" 0x000000 "NULL" "frFR"
|
||||
# "ad000001.smk" 107 start 30 "http://en.wikipedia.org/wiki/France" 0x00006E "NULL" "frFR"
|
||||
# "ad000001.smk" 108 init 30 "http://en.wikipedia.org/wiki/Italy" 0x000000 "NULL" "itIT"
|
||||
# "ad000001.smk" 109 start 30 "http://en.wikipedia.org/wiki/Italy" 0x00006E "NULL" "itIT"
|
||||
# "ad000001.smk" 110 norm 30 "http://pvpgn.berlios.de" 0x000000 "NULL" "any"
|
||||
|
||||
#
|
||||
|
||||
# Examples for different countries
|
||||
# "ad000001.smk" "http://en.wikipedia.org/wiki/Earth" "SEXP" "any"
|
||||
# "ad000001.smk" "http://en.wikipedia.org/wiki/Germany" "NULL" "deDE"
|
||||
# "ad000001.smk" "http://en.wikipedia.org/wiki/USA" "NULL" "enUS"
|
||||
# "ad000001.smk" "http://en.wikipedia.org/wiki/France" "NULL" "frFR"
|
||||
# "ad000001.smk" "http://en.wikipedia.org/wiki/Italy" "NULL" "itIT"
|
||||
# "ad000001.smk" "http://en.wikipedia.org/wiki/Russia" "NULL" "ruRU"
|
||||
# "ad000001.smk" "http://pvpgn.pro" "NULL" "any"
|
||||
# #
|
||||
##############################################################################
|
||||
|
|
Binary file not shown.
BIN
files/ad000001.png
Normal file
BIN
files/ad000001.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (C) 1999 Ross Combs (rocombs@cs.nmsu.edu)
|
||||
* Copyright (C) 2005 Dizzy
|
||||
* Copyright (C) 2014 HarpyWar
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
@ -217,10 +218,12 @@ namespace pvpgn
|
|||
bn_int bntag;
|
||||
if (strcasecmp(ext.c_str(), "pcx") == 0)
|
||||
bn_int_tag_set(&bntag, EXTENSIONTAG_PCX);
|
||||
else if (strcasecmp(ext.c_str(), "mng") == 0)
|
||||
bn_int_tag_set(&bntag, EXTENSIONTAG_MNG);
|
||||
else if (strcasecmp(ext.c_str(), "smk") == 0)
|
||||
bn_int_tag_set(&bntag, EXTENSIONTAG_SMK);
|
||||
else if (strcasecmp(ext.c_str(), "png") == 0)
|
||||
bn_int_tag_set(&bntag, EXTENSIONTAG_MNG);
|
||||
else if (strcasecmp(ext.c_str(), "mng") == 0)
|
||||
bn_int_tag_set(&bntag, EXTENSIONTAG_MNG);
|
||||
else {
|
||||
ERROR1("unknown extension on filename \"%s\"", fname.c_str());
|
||||
return;
|
||||
|
@ -298,12 +301,15 @@ namespace pvpgn
|
|||
throw SystemError("open");
|
||||
}
|
||||
|
||||
unsigned delay;
|
||||
unsigned next_id;
|
||||
unsigned id;
|
||||
// FIXME: (HarpyWar) this value is unused, because game clients retrieve ads in interval of ~20 seconds;
|
||||
// I think this is normal delay
|
||||
unsigned delay = 30;
|
||||
|
||||
std::string name, when, link, client, lang;
|
||||
std::vector<std::map<std::string, std::string>> tmplist;
|
||||
|
||||
std::string name, link, client, lang;
|
||||
std::string buff;
|
||||
// 1) Read ad.conf file
|
||||
for (unsigned line = 1; std::getline(fp, buff); ++line)
|
||||
{
|
||||
std::string::size_type idx(buff.find('#'));
|
||||
|
@ -315,15 +321,11 @@ namespace pvpgn
|
|||
std::istringstream is(buff);
|
||||
|
||||
is >> name;
|
||||
is >> id;
|
||||
is >> when;
|
||||
is >> delay;
|
||||
is >> link;
|
||||
is >> std::hex >> next_id;
|
||||
is >> client;
|
||||
is >> lang;
|
||||
|
||||
if (!is || name.size() < 2 || link.size() < 2 || client.size() < 2 || lang.size() < 2 || id < 1)
|
||||
if (!is || name.size() < 2 || link.size() < 2 || client.size() < 2 || lang.size() < 2)
|
||||
{
|
||||
ERROR2("malformed line %u in file \"%s\"", line, fname.c_str());
|
||||
continue;
|
||||
|
@ -338,20 +340,78 @@ namespace pvpgn
|
|||
lang.erase(0, 1);
|
||||
lang.erase(lang.size() - 1);
|
||||
|
||||
if (when == "init")
|
||||
insert(adlist_init, name, id, delay, link, next_id, client, lang);
|
||||
else if (when == "start")
|
||||
insert(adlist_start, name, id, delay, link, next_id, client, lang);
|
||||
else if (when == "norm")
|
||||
insert(adlist_norm, name, id, delay, link, next_id, client, lang);
|
||||
else
|
||||
/*
|
||||
ERROR4("when field has unknown value on line %u in file \"%s\": \"%s\" when == init: %d", line, fname.c_str(), when.c_str(), when == "init");
|
||||
*/
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "when field has unknown value on line %u in file \"%s\": \"%s\" when == init: %d", line, fname.c_str(), when.c_str(), when == "init");
|
||||
std::map<std::string, std::string> item;
|
||||
item["name"] = name;
|
||||
item["link"] = link;
|
||||
item["client"] = client;
|
||||
item["lang"] = lang;
|
||||
tmplist.push_back(item);
|
||||
}
|
||||
|
||||
unsigned id = 0;
|
||||
int init_count = 0;
|
||||
|
||||
bool first = true;
|
||||
std::map<std::string, int> tmpdata;
|
||||
AdCtagRefMap when;
|
||||
unsigned next_id;
|
||||
|
||||
// insert ads
|
||||
for (std::vector<std::map<std::string, std::string>>::iterator it = tmplist.begin(); it != tmplist.end(); ++it)
|
||||
{
|
||||
id++;
|
||||
tmpdata = get_rowdata(id, (*it)["client"], tmplist, init_count);
|
||||
next_id = tmpdata["next_id"];
|
||||
|
||||
if ((*it)["client"] == CLIENTTAG_WAR3XP || (*it)["client"] == CLIENTTAG_WARCRAFT3)
|
||||
{
|
||||
// warcraft 3 doesn't return previous ad id in SID_CHECKAD, and we must process all ADs as "init"
|
||||
// so they will be shown randomly
|
||||
insert(adlist_init, (*it)["name"], id, delay, (*it)["link"], id + 1, (*it)["client"], (*it)["lang"]);
|
||||
}
|
||||
else if (tmpdata["when"] == 1)
|
||||
{
|
||||
init_count++;
|
||||
// "init"
|
||||
insert(adlist_init, (*it)["name"], id, delay, (*it)["link"], id+1, (*it)["client"], (*it)["lang"]);
|
||||
id++;
|
||||
// and duplicate the same ad in "start"
|
||||
insert(adlist_start, (*it)["name"], id, delay, (*it)["link"], ++next_id, (*it)["client"], (*it)["lang"]);
|
||||
}
|
||||
else if (tmpdata["when"] > 1)
|
||||
{
|
||||
insert(adlist_norm, (*it)["name"], id, delay, (*it)["link"], next_id, (*it)["client"], (*it)["lang"]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, int> AdBannerComponent::get_rowdata(int id, std::string client, std::vector<std::map<std::string, std::string>> templist, int init_count)
|
||||
{
|
||||
std::vector<std::string> clients;
|
||||
std::map<std::string, int> data;
|
||||
|
||||
int tmpid = init_count;
|
||||
// find clienttag
|
||||
for (std::vector<std::map<std::string, std::string>>::iterator it = templist.begin(); it != templist.end(); ++it)
|
||||
{
|
||||
tmpid++;
|
||||
if ((*it)["client"] == client)
|
||||
{
|
||||
if (tmpid <= id)
|
||||
data["when"]++;
|
||||
|
||||
// set next_id if value is not greater of max size
|
||||
if (tmpid > id)
|
||||
{
|
||||
data["next_id"] = tmpid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
AdBannerComponent::~AdBannerComponent() throw()
|
||||
{}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "common/tag.h"
|
||||
#include "common/scoped_ptr.h"
|
||||
|
@ -83,6 +84,7 @@ namespace pvpgn
|
|||
const AdBanner* findRandom(const AdCtagRefMap& where, AdKey adKey) const;
|
||||
const AdBanner* randomFinder(const AdCtagRefMap& where, AdKey adKey) const;
|
||||
void insert(AdCtagRefMap& where, const std::string& fname, unsigned id, unsigned delay, const std::string& link, unsigned next_id, const std::string& client, const std::string& lang);
|
||||
std::map<std::string, int> get_rowdata(int id, std::string client, std::vector<std::map<std::string, std::string>> templist, int init_count);
|
||||
};
|
||||
|
||||
extern scoped_ptr<AdBannerComponent> adbannerlist;
|
||||
|
|
Loading…
Reference in a new issue