Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Working Fame (revised)

Status
Not open for further replies.
Newbie Spellweaver
Joined
Apr 22, 2008
Messages
54
Reaction score
0
What you need you to do

- Take a very deep breath before reading, yea seriously :p
- 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::playerConnect())

Code:
fameOffset = MySQL::getInt("characters", getPlayerid(), "UNIX_TIMESTAMP()-UNIX_TIMESTAMP(last_famed)");
Add:

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:
Master Summoner
Joined
Apr 2, 2008
Messages
538
Reaction score
0
Re: [RELEASE] Fame Packets

I'll test it out.
 
Experienced Elementalist
Joined
Dec 7, 2006
Messages
294
Reaction score
0
Re: [RELEASE] Fame Packets

Nice release mate, keep it up ;)
I'll try to code it myself :p
 
Junior Spellweaver
Joined
Dec 18, 2006
Messages
174
Reaction score
0
Re: [RELEASE] Fame Packets

Great :)

i can test if you want or need.
 
Newbie Spellweaver
Joined
Apr 22, 2008
Messages
54
Reaction score
0
Re: [RELEASE] Working Fame

@all: hey glad you all liked it :)

@Sh3rC4n: thanks for lending a hand, i rigged up another pc before i read your reply :p


client appears to crash for the player doing the faming. updated my first post with working code and additional packets missing that is causing the EOF errors (highlighted in bold).
 
Master Summoner
Joined
Apr 2, 2008
Messages
538
Reaction score
0
Re: [RELEASE] Working Fame

Elite release.
 
Experienced Elementalist
Joined
Apr 2, 2007
Messages
260
Reaction score
1
Re: [RELEASE] Working Fame

No check for 24 hrs/30 days.
 
Newbie Spellweaver
Joined
Mar 14, 2008
Messages
89
Reaction score
0
Re: [RELEASE] Working Fame

SlaYaH he said to implement MySQL for response 3 and 4:

Code:
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



You will need to implement a little bit of MySQL for response 3 and 4.
 
Experienced Elementalist
Joined
Apr 2, 2007
Messages
260
Reaction score
1
Re: [RELEASE] Working Fame

SlaYaH he said to implement MySQL for response 3 and 4:

Code:
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

Then it isn't "working" fame. Plus the character being famed won't refresh when he hits "s"
 
Newbie Spellweaver
Joined
Apr 4, 2008
Messages
49
Reaction score
0
Re: [RELEASE] Working Fame

Then it isn't "working" fame. Plus the character being famed won't refresh when he hits "s"

lol Oo did you even read what that packets does ?
the fame is working but you can fame alot instead of 1 time
why wouldn't it refresh ? T-T
 
Experienced Elementalist
Joined
Apr 2, 2007
Messages
260
Reaction score
1
Re: [RELEASE] Working Fame

lol Oo did you even read what that packets does ?
the fame is working but you can fame alot instead of 1 time
why wouldn't it refresh ? T-T

It isn't even close to "working."
 
Newbie Spellweaver
Joined
Apr 5, 2008
Messages
44
Reaction score
0
Re: [RELEASE] Working Fame

You forgot to add in your post that you need to add this to PlayerPacket.h
Code:
static void fame(Player* player, unsigned char* pack);


but, great release =)
 
Master Summoner
Joined
Apr 2, 2008
Messages
538
Reaction score
0
Re: [RELEASE] Working Fame

I guess its not such a elite release after all ;/
 
Newbie Spellweaver
Joined
Apr 22, 2008
Messages
54
Reaction score
0
Re: [RELEASE] Working Fame

thanks for the feedback guys.

updated the code to sync your fame when u press 'S'

the checks to responses 3 and 4 are quite straight forward, a new 'fame' table and a new column in your 'characters' table will do.
 
Newbie Spellweaver
Joined
Feb 19, 2008
Messages
33
Reaction score
0
Re: [RELEASE] Working Fame

Great, now i can stop working on mine it was sort of like this.
 
Newbie Spellweaver
Joined
Jul 25, 2007
Messages
32
Reaction score
0
Re: [RELEASE] Working Fame

wtf :(

.\PlayerPacket.cpp(296) : error C3861: 'getInt': identifier not found
.\PlayerPacket.cpp(297) : error C3861: 'getInt': identifier not found
.\PlayerPacket.cpp(301) : error C2653: 'Players' : is not a class or namespace name
.\PlayerPacket.cpp(301) : error C2065: 'players' : undeclared identifier
.\PlayerPacket.cpp(301) : error C2228: left of '.begin' must have class/struct/union
type is ''unknown-type''
.\PlayerPacket.cpp(301) : error C2653: 'Players' : is not a class or namespace name
.\PlayerPacket.cpp(301) : error C2065: 'players' : undeclared identifier
.\PlayerPacket.cpp(301) : error C2228: left of '.end' must have class/struct/union
type is ''unknown-type''
 
Junior Spellweaver
Joined
Sep 27, 2006
Messages
195
Reaction score
1
Re: [RELEASE] Working Fame

wtf :(

.\PlayerPacket.cpp(296) : error C3861: 'getInt': identifier not found
.\PlayerPacket.cpp(297) : error C3861: 'getInt': identifier not found
.\PlayerPacket.cpp(301) : error C2653: 'Players' : is not a class or namespace name
.\PlayerPacket.cpp(301) : error C2065: 'players' : undeclared identifier
.\PlayerPacket.cpp(301) : error C2228: left of '.begin' must have class/struct/union
type is ''unknown-type''
.\PlayerPacket.cpp(301) : error C2653: 'Players' : is not a class or namespace name
.\PlayerPacket.cpp(301) : error C2065: 'players' : undeclared identifier
.\PlayerPacket.cpp(301) : error C2228: left of '.end' must have class/struct/union
type is ''unknown-type''

same also HELP!!!!!!!!!!!!!!!!!!!
 
Status
Not open for further replies.
Back
Top