fixed citymania cb sync and user sync

This commit is contained in:
Pavel Stupnikov
2015-06-15 15:52:05 +03:00
parent ad67312e2d
commit fc0c2fe15b
5 changed files with 45 additions and 69 deletions

View File

@@ -21,11 +21,12 @@ IniFile *_inilogin = NULL;
static const int HTTPBUFLEN = 128;
// nova* stuff probabaly obsolete
static const char * const NOVAPOLIS_IPV4_PRIMARY = "37.157.196.78";
static const char * const NOVAPOLIS_IPV6_PRIMARY = "2a02:2b88:2:1::1d73:1";
static const char * const NOVAPOLIS_IPV4_SECONDARY = "89.111.65.225";
static const char * const NOVAPOLIS_IPV6_SECONDARY = "fe80::20e:7fff:fe23:bee0";
static const char * const NOVAPOLIS_STRING = "novapolis";
static const char * const NOVAPOLIS_STRING = "CityMania";
static const char * const NICE_HTTP_LOGIN = "http://n-ice.org/openttd/gettoken.php?user=%s&password=%s";
static const char * const BTPRO_HTTP_LOGIN = "http://openttd.btpro.nl/gettoken.php?user=%s&password=%s";
@@ -170,17 +171,7 @@ void AccountLogin(CommunityName community);
void IniReloadLogin();
char * GetLoginItem(const char * item);
bool novahost(){
_novahost = false;
for(int i = 0, len = lengthof(NOVA_IP_ADDRESSES); i < len; i++){
if(strcmp(_settings_client.network.last_host, NOVA_IP_ADDRESSES[i]) == 0){
_novahost = true;
break;
}
}
if(_novahost == false && strstr(_settings_client.network.last_host, NOVAPOLIS_STRING) != NULL){
_novahost = true;
}
bool novahost() {
return _novahost;
}

View File

@@ -40,7 +40,7 @@
#include "../safeguards.h"
/* This file handles all the client-commands */
void SyncCBClient(byte * msg);
void SyncCMUser(const char *msg);
/** Read some packets, and when do use that data as initial load filter. */
struct PacketReader : LoadFilter {
@@ -269,9 +269,8 @@ void ClientNetworkGameSocketHandler::ClientError(NetworkRecvStatus res)
_network_first_time = false;
SendAck();
extern bool novahost();
if(novahost()){
NetworkClientSendChatToServer("!check 1444"); //check version
CB_SetCB(false);
if(novahost()) {
NetworkClientSendChatToServer("!check 1512"); //check version
}
}
@@ -1000,7 +999,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p)
}
if (ci != NULL) {
if (strncmp(msg, "synccbclient", 12) == 0) SyncCBClient(p->buffer);
if (strncmp(msg, "synccmuser", 10) == 0) SyncCMUser(msg);
else NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), self_send, name, msg, data);
}
return NETWORK_RECV_STATUS_OKAY;
@@ -1323,49 +1322,11 @@ bool NetworkMaxSpectatorsReached()
return NetworkSpectatorCount() >= (_network_server ? _settings_client.network.max_spectators : _network_server_max_spectators);
}
void SyncCBClient(byte *msg){ //len = 3 + 6 + 12 + 3 + 6*cargo
size_t pos = 21;
size_t length = pos;
byte tmp;
while(msg[length] != '\0'){ length++; }
_novarole = msg[pos++] == 'A';
if(length == pos) return;
CB_SetCB(true);
tmp = msg[pos++];
_settings_client.gui.cb_distance_check = (tmp == 0xFF) ? 0 : tmp;
tmp = msg[pos++];
CB_SetStorage((tmp == 0xFF) ? 0 : (uint)tmp);
for(int i = 0; i < NUM_CARGO; i++){
CB_SetRequirements(i, 0, 0, 0);
}
//IConsolePrintF(CC_INFO, "cb check %i, storage %i", _settings_client.gui.cb_distance_check, tmp);
uint8 cargo;
uint req, from, decay;
while(pos < length){ //CargoID NUM_CARGO
cargo = msg[pos++];
if(cargo == 0xFF) cargo = 0;
tmp = msg[pos++];
req = (tmp == 0xFF) ? 0 : tmp;
tmp = msg[pos++];
req += (tmp == 0xFF) ? 0 : (tmp << 8);
tmp = msg[pos++];
from = (tmp == 0xFF) ? 0 : tmp;
tmp = msg[pos++];
from += (tmp == 0xFF) ? 0 : (tmp << 8);
tmp = msg[pos++];
decay = (tmp == 0xFF) ? 0 : tmp;
CB_SetRequirements(cargo, req, from, decay);
//IConsolePrintF(CC_INFO, "cargo#%i %i/%i/%i", cargo, req, from, decay);
}
void SyncCMUser(const char *msg) {
uint user_id, role;
fprintf(stderr, "oaeu [%s]\n", msg);
sscanf(msg + 10, "%u %u", &user_id, &role);
_novarole = (role >= 50);
DEBUG(net, 1, "CityMania user synchronized: %u %u", user_id, role);
}
#endif /* ENABLE_NETWORK */

View File

@@ -15,13 +15,13 @@ static void CM_EncodeTownsExtraInfo(BitOStream &bs)
uint n_affected_towns = 0;
FOR_ALL_TOWNS(t) {
if (t->growing_by_chance || t->houses_reconstruction ||
t->houses_construction || t->houses_demolished)
t->houses_demolished)
n_affected_towns++;
}
bs.WriteBytes(n_affected_towns, 2);
FOR_ALL_TOWNS(t) {
if (t->growing_by_chance || t->houses_reconstruction ||
t->houses_construction || t->houses_demolished) {
t->houses_demolished) {
bs.WriteBytes(t->index, 2);
bs.WriteBytes(t->growing_by_chance, 1);
bs.WriteBytes(t->houses_reconstruction, 2);
@@ -76,6 +76,8 @@ static void CM_EncodeTownsCargo(BitOStream &bs)
cb_cargos[n_cb_cargos++] = cargo;
}
bs.WriteBytes(CB_GetStorage(), 1);
bs.WriteBytes(_settings_client.gui.cb_distance_check, 1);
bs.WriteBytes(n_cb_cargos, 1);
for (uint i = 0; i < n_cb_cargos; i++) {
CargoID cargo = cb_cargos[i];
@@ -153,6 +155,8 @@ static void CM_DecodeTownsLayoutErrors(BitIStream &bs)
static void CM_DecodeTownsCargo(BitIStream &bs)
{
CB_SetStorage(bs.ReadBytes(1));
_settings_client.gui.cb_distance_check = bs.ReadBytes(1);
uint n_cb_cargos = bs.ReadBytes(1);
CB_ResetRequirements();
CargoID cb_cargos[NUM_CARGO];
@@ -192,6 +196,8 @@ u8vector CM_EncodeData()
BitOStream bs;
bs.Reserve(1000);
bs.WriteBytes(CM_DATA_FORMAT_VERSION, 2);
bs.WriteBytes(1512, 2); // TODO client version
bs.WriteBytes(CB_Enabled(), 1);
bs.WriteBytes(_date, 4); // Just in case we'll need to detect that game
bs.WriteBytes(_date_fract, 1); // was saved by unmodified client
bs.WriteBytes(0, 4); // Reserved
@@ -214,13 +220,15 @@ u8vector CM_EncodeData()
void CM_DecodeData(u8vector &data)
{
ResetTownsGrowthTiles();
extern bool _novahost;
if (data.size() == 0) {
_novahost = false;
CB_SetCB(false);
DEBUG(sl, 2, "No citybuilder data");
return;
}
DEBUG(sl, 2, "Citybuilder data takes %lu bytes", data.size());
CB_SetCB(true);
_novahost = true;
BitIStream bs(data);
try {
uint version = bs.ReadBytes(2);
@@ -228,11 +236,20 @@ void CM_DecodeData(u8vector &data)
DEBUG(sl, 0, "Savegame was made with different version of client, extra citybuilder data was not loaded");
return;
}
bs.ReadBytes(4); // _date
bs.ReadBytes(1); // _date_fract
bs.ReadBytes(2); // client version
bool is_cb = bs.ReadBytes(1);
CB_SetCB(is_cb);
int32 date = bs.ReadBytes(4); // date
uint32 date_fract = bs.ReadBytes(1); // date_fract
if (date != _date || date_fract != _date_fract) {
DEBUG(sl, 0, "Savegame was run in unmodified client, extra cb data "
"preserved, but may not be accurate");
}
bs.ReadBytes(4); // reserved
bs.ReadBytes(4); // reserved
CM_DecodeTownsCargo(bs);
if (is_cb) {
CM_DecodeTownsCargo(bs);
}
CM_DecodeTownsExtraInfo(bs);
CM_DecodeTownsLayoutErrors(bs);
}

View File

@@ -254,6 +254,7 @@ const CargoSpec *FindFirstCargoWithTownEffect(TownEffect effect);
bool CB_Enabled();
void CB_SetCB(bool cb);
uint CB_GetStorage();
void CB_SetStorage(uint storage);
void CB_SetRequirements(CargoID cargo, uint req, uint from, uint decay);
void CB_ResetRequirements();

View File

@@ -1693,9 +1693,15 @@ void CB_SetCB(bool cb){
CB_ResetRequirements();
}
}
uint CB_GetStorage() {
return _cb_storage;
}
void CB_SetStorage(uint storage){
_cb_storage = storage;
}
void CB_SetRequirements(CargoID cargo, uint req, uint from, uint decay){
CBREQ[cargo] = req;
CBFROM[cargo] = from;
@@ -3686,8 +3692,6 @@ void TownsMonthlyLoop()
}
if (CB_Enabled() && !t->larger_town) CB_UpdateTownStorage(t); //CB
t->houses_demolished = 0;
t->houses_reconstruction = 0;
UpdateTownAmounts(t);
UpdateTownRating(t);
@@ -3697,6 +3701,8 @@ void TownsMonthlyLoop()
DoRegularFunding(t);
t->houses_demolished = 0;
t->houses_reconstruction = 0;
t->houses_skipped_last_month = t->houses_skipped - t->houses_skipped_prev;
t->houses_skipped_prev = t->houses_skipped;
t->cycles_skipped_last_month = t->cycles_skipped - t->cycles_skipped_prev;