The goal was to toggle 1/0 for when a player logs in or out of the World. The value stays persistent across zones, and only gets set back to 0 when the client loses connection (Client::Disconnect()).
Give it a look, if you think it's fine, I can check it in.
Code: Select all
Index: client.cpp
===================================================================
--- client.cpp (revision 689)
+++ client.cpp (working copy)
@@ -592,6 +592,7 @@
new_client_login = true;
GetCurrentZone()->AddClient(this); //add to zones client list
zone_list.AddClientToMap(player->GetName(), this);
+ database.ToggleCharacterOnline(this, 1);
}
else{
cout << "Incompatible version : " << version << endl;
@@ -1613,6 +1614,7 @@
void Client::Disconnect(){
if(getConnection())
getConnection()->SendDisconnect(true);
+ database.ToggleCharacterOnline(this, 0);
eqs = 0;
}
Index: WorldDatabase.cpp
===================================================================
--- WorldDatabase.cpp (revision 689)
+++ WorldDatabase.cpp (working copy)
@@ -3189,4 +3189,13 @@
}
columns.append("");
return columns;
+}
+
+void WorldDatabase::ToggleCharacterOnline(Client* client, int8 toggle) {
+ Query query;
+ Player* player = client->GetPlayer();
+ if(!player->CheckPlayerInfo())
+ return;
+
+ query.RunQuery2(Q_UPDATE, "update characters set is_online=%i where id = %lu", toggle, client->GetCharacterID());
}
\ No newline at end of file
Index: WorldDatabase.h
===================================================================
--- WorldDatabase.h (revision 689)
+++ WorldDatabase.h (working copy)
@@ -208,6 +208,9 @@
}
void LoadFogInit(string zone, PacketStruct* packet);
static int32 next_id;
+
+ void ToggleCharacterOnline(Client* client, int8 toggle);
+
private:
map<int32, string> zone_names;
string skills;DB Change:
Code: Select all
alter table `characters` add column `is_online` tinyint(1) UNSIGNED DEFAULT '0' NOT NULL;Note: I am not completely sure "Player* player = client->GetPlayer();" is needed. I copied how Client::Save() worked and took out what I didn't need.