What you need you to do
- Take a very deep breath before reading, yea seriously
- Open your eyes BIG
- If you run into problems
* GO THROUGH the thread. Wonderful people might have already posted solutions to your problems.
* DONT just post your error messages just because you got them. READ and make sense out of the error messages and try to resolve them.
Packet Information
Header: 31 00
Response (Byte): (see below)
Short: Player name length
* followed by player name
Byte: 0 (drop fame) / 1 (raise fame)
Short: new fame value (response 0 only)
Short: 00 (response 0 only)
Response
0 - You have dropped/raised '<target name>' level of fame
1 - The user name is incorrectly entered
2 - Users under level 15 are unable to toggle with fame
3 - You can't raise or drop a level of fame anymore for today
4 - You can't raise or drop a level of fame of that character anymore for this month
5 - '<target name>' have dropped/raised '<Player name>''s level of fame
* You may omit packets 'player name length' onwards if your response is not 0 or 5
* You need to include the 2 x short packets at the end if you are sending a response 0 packet. Failure to do so will crash the client with an end of file error.
Example
Let's say you are adding fame to a player name zouker and his new fame is 10
The server will send this to you
31 00 00 06 7A 6F 75 6B 65 72 01 0A 00 00 00
And the server will send this to zouker
31 00 05 06 7A 6F 75 6B 65 72 01
CODE
Playerpacket.h
Add: (thanks aawaiaa
Playerpacket.cpp
Add:
Player.h
Add: (under public
Add: (under private
Replace:
With:
Player.cpp
Add:
Add: (under void Player:layerConnect())
Add:
The following code is taken from [Release] GMSDB Beta3 Rev1[NEW UPDATES] - Fully driven SQL databasing for TitanMS. If your server is already using it, you do not need to add this. (Credits to doyos)
MySQLM.h
Add: (under public
MySQLM.cpp
Add:
DATABASE STRUCTURE
HELPFUL HINTS from the community
Now get yourself a cup of coffee, you deserved it.
This is like the longest post i've done in like 10 years :juggle:
Let me know how it turns out
- Take a very deep breath before reading, yea seriously
- Open your eyes BIG
- If you run into problems
* GO THROUGH the thread. Wonderful people might have already posted solutions to your problems.
* DONT just post your error messages just because you got them. READ and make sense out of the error messages and try to resolve them.
Packet Information
Header: 31 00
Response (Byte): (see below)
Short: Player name length
* followed by player name
Byte: 0 (drop fame) / 1 (raise fame)
Short: new fame value (response 0 only)
Short: 00 (response 0 only)
Response
0 - You have dropped/raised '<target name>' level of fame
1 - The user name is incorrectly entered
2 - Users under level 15 are unable to toggle with fame
3 - You can't raise or drop a level of fame anymore for today
4 - You can't raise or drop a level of fame of that character anymore for this month
5 - '<target name>' have dropped/raised '<Player name>''s level of fame
* You may omit packets 'player name length' onwards if your response is not 0 or 5
* You need to include the 2 x short packets at the end if you are sending a response 0 packet. Failure to do so will crash the client with an end of file error.
Example
Let's say you are adding fame to a player name zouker and his new fame is 10
The server will send this to you
31 00 00 06 7A 6F 75 6B 65 72 01 0A 00 00 00
And the server will send this to zouker
31 00 05 06 7A 6F 75 6B 65 72 01
CODE
Playerpacket.h
Add: (thanks aawaiaa
Code:
static void fame(Player* player, unsigned char* pack);
static void newFame(Player* player);
Playerpacket.cpp
Add:
Code:
void PlayerPacket::newFame(Player* player){ // zouker@ragezone :p
Packet packet = Packet();
packet.addHeader(0x23);
packet.addShort(0);
packet.addShort(0);
packet.addShort(2);
packet.addShort(player->getFame());
packet.packetSend(player);
}
void PlayerPacket::fame(Player* player, unsigned char* pack){
/* written by: zouker@ragezone
Response table
0 - You have dropped '' level of fame
1 - The user name is incorrectly entered
2 - Users under level 15 are unable to toggle with fame
3 - You can't raise or drop a level of fame anymore for today
4 - You can't raise or drop a level of fame of that character anymore for this month
5 - '' have dropped '''s level of fame
*/
int hours = 24; // hours before next fame
int days = 30; // days before next fame of the same person
int charid = getInt(pack);
unsigned char fame = getInt(pack+4);
Packet packet = Packet();
packet.addHeader(0x31);
if(player->getLevel()<15){
packet.addByte(2);
}
else if(player->getFameOffset() < hours*60*60){
packet.addByte(3);
}
else if(!player->canFamePlayer(charid, days)){
packet.addByte(4);
}
else {
bool found = false;
for (hash_map < int, Player* >::iterator iter = Players::players.begin(); iter != Players::players.end(); iter++){
// iter->second gets the second item in the hash map
if (iter->first == charid){
if (fame == 1)
iter->second->setFame(iter->second->getFame()+1);
else
iter->second->setFame(iter->second->getFame()-1);
player->setFameOffset();
player->setFameOffset(iter->first);
packet.addByte(0);
packet.addShort(strlen(iter->second->getName()));
packet.addString(iter->second->getName(), strlen(iter->second->getName()));
packet.addByte(fame);
packet.addShort(iter->second->getFame());
packet.addShort(0);
Packet packet2 = Packet();
packet2.addHeader(0x31);
packet2.addByte(5);
packet2.addShort(strlen(player->getName()));
packet2.addString(player->getName(), strlen(player->getName()));
packet2.addByte(fame);
packet.addShort(iter->second->getFame());
packet2.packetSend(iter->second);
newFame(iter->second);
found = true;
break;
}
}
if (!found) packet.addByte(1);
}
packet.packetSend(player);
}
Player.h
Add: (under public
Code:
bool canFamePlayer(int famed_id, int days);
void setFameOffset();
void setFameOffset(int famedId);
int getFameOffset(){
return this->fameOffset;
}
Add: (under private
Code:
int fameOffset;
Replace:
Code:
void setFame(short fame);
{
this->fame=fame;
}
With:
Code:
void setFame(short fame);
Player.cpp
Add:
Code:
case 0x69: PlayerPacket::fame(this, buf+2);break;
Add: (under void Player:layerConnect())
Code:
fameOffset = MySQL::getInt("characters", getPlayerid(), "UNIX_TIMESTAMP()-UNIX_TIMESTAMP(last_famed)");
Code:
bool Player::canFamePlayer(int famedId, int days){ // added to check if the player can fame the same person again - zouker@ragezone
MYSQL_RES *mres;
char sql[255];
sprintf_s(sql, 255, "SELECT * FROM famedata WHERE ID=%d AND userid=%d AND UNIX_TIMESTAMP(last_famed) > UNIX_TIMESTAMP()-%d*86400", famedId, this->id, days);
mres = MySQL::getRes(sql);
return (mysql_num_rows(mres)== 0) ? true : false;
}
void Player::setFameOffset(){ // updates the time so that the player cannot fame again until 24 hours later - zouker@ragezone
char sql[255];
sprintf_s(sql, 255, "UPDATE characters SET last_famed=NOW() WHERE ID=%d", this->id);
MySQL::insert(sql);
this->fameOffset = MySQL::getInt("characters", getPlayerid(), "UNIX_TIMESTAMP()-UNIX_TIMESTAMP(last_famed)");
}
void Player::setFameOffset(int famedId){ // inserts a record in the famedata table which contains a list of people the player had famed - zouker@ragezone
char sql[255];
sprintf_s(sql, 255, "INSERT INTO famedata (ID, userid, last_famed) VALUES(%d, %d, NOW()) ON DUPLICATE KEY UPDATE last_famed=NOW()", famedId, this->id);
MySQL::insert(sql);
}
void Player::setFame(short fame){ // updates the player's fame in case of server crashes xD - zouker@ragezone
char sql[255];
sprintf_s(sql, 255, "UPDATE characters SET fame=%d WHERE ID=%d", fame, this->id);
MySQL::insert(sql);
this->fame=fame;
}
The following code is taken from [Release] GMSDB Beta3 Rev1[NEW UPDATES] - Fully driven SQL databasing for TitanMS. If your server is already using it, you do not need to add this. (Credits to doyos)
MySQLM.h
Add: (under public
Code:
static MYSQL_RES* getRes(char *query);
MySQLM.cpp
Add:
Code:
MYSQL_RES* MySQL::getRes(char *query){
MYSQL_RES *mres;
char sql[500];
strcpy_s(sql, 500, query);
mysql_real_query(&MySQL::maple_db, sql, strlen(sql));
mres = mysql_store_result(&MySQL::maple_db);
return mres;
}
DATABASE STRUCTURE
Code:
ALTER TABLE `characters` ADD `last_famed` DATETIME NOT NULL
Code:
CREATE TABLE `famedata` (`ID` INT NOT NULL, `userid` INT NOT NULL, `last_famed` DATETIME NOT NULL)
Code:
ALTER TABLE `famedata` ADD PRIMARY KEY (`ID` , `userid`)
HELPFUL HINTS from the community
Great work!
I had to change a few things though:
add #include "Players.h" to PlayerPacket.cpp
add int getInt(unsigned char* buf); to PlayerPacket.cpp
add a default value for the last_famed column
Maybe this will help others
Now get yourself a cup of coffee, you deserved it.
This is like the longest post i've done in like 10 years :juggle:
Let me know how it turns out
Last edited: