• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Jan 12 2007] Fully working CTRL+R (Report Violation)

ragal

Member
Joined
Nov 29, 2007
Messages
735
Reaction score
19
Location
Germany - Berlin
Works 100% for me :) Credits: El Peekay, and me :p
Note: This was made for CLEAN SVN, you'll need to do some edits to add it to forgotten server(Talaturen is making one anyways ;P)

protocol80.cpp
replace
Quote:
case 0x14: // logout
parseLogout(msg);
break;
with Code:
PHP:
	case 0x14: // logout
	#ifdef SDG_VIOLATIONS
    if (player->hasOpenViolation) cancelViolation(player->getName());
#endif
		parseLogout(msg);
		break;

further down, add
Code:

PHP:
#ifdef SDG_VIOLATIONS
    case 0x9B: // send report (reportee)
        openViolation(msg);
    break;
    
    case 0x9C: // close report (gm)
        closeViolation(msg);
    break;
    
    case 0x9D: // cancel report (reportee) -- Vitor packetid
        cancelViolation(player->getName());
    break;
    
#endif

replace

PHP:
void Protocol80::parseOpenChannel(NetworkMessage& msg)
{
uint16_t channelId = msg.GetU16();
OTSYS_THREAD_LOCK_CLASS lockClass(g_game.gameLock, "Protocol79::parseOpenChannel()");
if(player->isRemoved()){
return;
}
if(g_chat.addUserToChannel(player, channelId)){
sendChannel(channelId, g_chat.getChannelName(player, channelId));
}
}
with
Code:

void Protocol80::parseOpenChannel(NetworkMessage& msg)
{
	uint16_t channelId = msg.GetU16();
	OTSYS_THREAD_LOCK_CLASS lockClass(g_game.gameLock, "Protocol79::parseOpenChannel()");
	if(player->isRemoved()){
		return;
	}
#ifdef SDG_VIOLATIONS
    if (channelId == 0x03 && player->getAccessLevel() >= 2) // violations only for couns++
    {    sendViolationChannel(player);  return; }
    else{
#endif
	if(g_chat.addUserToChannel(player, channelId)){
		sendChannel(channelId, g_chat.getChannelName(player, channelId));
	}
	#ifdef SDG_VIOLATIONS
}
#endif
}

void Protocol80::parseSay(NetworkMessage& msg)
replace whole function with...
Code:

void Protocol80::parseSay(NetworkMessage& msg)
{
	SpeakClasses type = (SpeakClasses)msg.GetByte();

	std::string receiver = "";
	unsigned short channelId = 0;
	if(type == SPEAK_PRIVATE ||
	#ifdef SDG_VIOLATIONS
        type == SPEAK_CHANNEL_RV2 || 
#endif
	type == SPEAK_PRIVATE_RED)
		receiver = msg.GetString();
	if(type == SPEAK_CHANNEL_Y ||
		type == SPEAK_CHANNEL_R1 ||
		type == SPEAK_CHANNEL_R2)
		channelId = msg.GetU16();
	std::string text = msg.GetString();

	g_game.playerSay(player, channelId, type, receiver, text);
}


at the bottom
Code:
PHP:
#ifdef SDG_VIOLATIONS
// ...let the fun start...
// True Violations handling -by- SumDumGuy
// coded March 31 - April 1st 2006 
// bombproofed and tested to death on Nuuberland - Apr 2-8 
// - released to public + submitted for CVS inclusion Apr 8th -
// PacketId bytes found by Vitor - 0x9D (recv) , 0xB1 (send)
// all the rest and packet formats found by me >;)
// - edit to desired protocol classname -

void Protocol80::addViolation(Player* reporter, std::string message)
{// reporter files report
	OTSYS_THREAD_LOCK_CLASS lockClass(g_game.gameLock, "Protocol79::addViolation()");
    reporter->violationTime = OTSYS_TIME();
    reporter->violationReport = message;
    reporter->hasOpenViolation = true;
    
    g_game.openViolations.push_back(reporter);
    
    NetworkMessage msg;
    msg.AddByte(0xAA);
    msg.AddU32(0);
    msg.AddString(reporter->getName());
    msg.AddU16(0); //level
    msg.AddByte(SPEAK_CHANNEL_RV1);
    msg.AddU32(0x00000000); // cause its 0 secs since report ;p
    msg.AddString(reporter->violationReport);
    updateViolationsChannel(msg);
}

void Protocol80::removeViolation(std::string rname)
{ // close off open violation - reporter logout/cancelled or gm answers
	OTSYS_THREAD_LOCK_CLASS lockClass(g_game.gameLock, "Protocol79::removeViolation()");
    NetworkMessage msg;
    Player* reporter = g_game.getPlayerByName(rname);
    if (reporter && reporter->hasOpenViolation)
    {
        msg.AddByte(0xAF);
        msg.AddString(rname);
        updateViolationsChannel(msg);
    
        for(std::vector<Player*>::iterator it = g_game.openViolations.begin(); it != g_game.openViolations.end(); ++it) 
        { // iterate thru vector and pop out the one matching this guy's
            if ((*it) && (*it)->getName() == rname) // its 'ours'
            {
                (*it)->hasOpenViolation = false;
                (*it)->violationName = "";
                (*it)->violationTime = 0;
                (*it)->violationReport = "";
                g_game.openViolations.erase(it);
                return; // leave or crash 
            }
        }
    }
}

void Protocol80::cancelViolation(std::string rname)
{// reporter cancels report
	OTSYS_THREAD_LOCK_CLASS lockClass(g_game.gameLock, "Protocol79::cancelViolation()");
    NetworkMessage msg;
    Player* gm = g_game.getPlayerByName(player->violationName);
    if (gm)
    { // has attached gm

         //msg.AddU32(0);
        msg.AddByte(0xB0); // lock gm's channel
        msg.AddString(rname);
        gm->sendNetworkMessage(&msg);
        
        gm->violationName = "";
        player->violationName = "";
    }
    removeViolation(rname);
    
}

void Protocol80::openViolation(NetworkMessage &msg)
{ // gm answers report in violations window
	OTSYS_THREAD_LOCK_CLASS lockClass(g_game.gameLock, "Protocol79::openViolation()");
    std::string rname = msg.GetString();
    NetworkMessage newmsg;
    
    Player* reporter = g_game.getPlayerByName(rname);
    if (reporter)
    {
        removeViolation(rname);
        
        reporter->violationName = player->getName();
        player->violationName = rname;
    }

}

void Protocol80::closeViolation(NetworkMessage &msg)
{ // report done and gm closes their end
	OTSYS_THREAD_LOCK_CLASS lockClass(g_game.gameLock, "Protocol79::closeViolation()");
    std::string rname = msg.GetString();
    NetworkMessage newmsg;
    
    Player* reporter = g_game.getPlayerByName(rname);
    
    if (reporter)
    {
        if (reporter->hasOpenViolation) removeViolation(rname);
        
        newmsg.AddByte(0xB1);   // Vitor - packetid byte - locks reporters channel
        reporter->sendNetworkMessage(&newmsg);

        reporter->violationName = "";
        player->violationName = "";
    }
    
}

void Protocol80::speakToReporter(std::string rname, std::string message)
{ // gm/couns to reportee
	OTSYS_THREAD_LOCK_CLASS lockClass(g_game.gameLock, "Protocol79::speakToReporter()");
    NetworkMessage newmsg;
    Player* reporter = g_game.getPlayerByName(rname);
    
    if (reporter)
    {// send message
        newmsg.AddByte(0xAA);
        newmsg.AddU32(0);
        newmsg.AddString("Counsellor");
        newmsg.AddU16(0); //level
        newmsg.AddByte(SPEAK_CHANNEL_RV2);
        newmsg.AddString(message);
        reporter->sendNetworkMessage(&newmsg);
    // send status text 
        newmsg.Reset();
        newmsg.AddByte(0xB4);
        newmsg.AddByte(MSG_STATUS_SMALL);
        std::stringstream ss;
        ss << "Message sent to " << reporter->getName() << ".";
        newmsg.AddString(ss.str());
        WriteBuffer(newmsg);
    }
   
}

void Protocol80::speakToCounsellor(std::string message)
{ // reportee to couns/gm
	OTSYS_THREAD_LOCK_CLASS lockClass(g_game.gameLock, "Protocol79::speakToCounsellor()");
    NetworkMessage newmsg;
    Player* gm = g_game.getPlayerByName(player->violationName);
    
    if (gm)
    {
        newmsg.AddByte(0xAA);
        newmsg.AddU32(0);
        newmsg.AddString(player->getName());
        newmsg.AddU16(0); //level
        newmsg.AddByte(SPEAK_CHANNEL_RV3);
        newmsg.AddString(message.c_str());
        gm->sendNetworkMessage(&newmsg);
    // send status text 
        newmsg.Reset();
        newmsg.AddByte(0xB4);
        newmsg.AddByte(MSG_STATUS_SMALL);
        newmsg.AddString("Message sent to Counsellor.");
        WriteBuffer(newmsg);
    }
    
}

void Protocol80::updateViolationsChannel(NetworkMessage &update) // gamelock in add/remove
{// update all open violation channels
    for(AutoList<Player>::listiterator it = Player::listPlayer.list.begin(); it != Player::listPlayer.list.end(); ++it)
        if ((*it).second->hasViolationsChannelOpen)
            (*it).second->sendNetworkMessage(&update);

}

void Protocol80::sendViolationChannel(Player* gm) // gamelock in send channel
{ // couns/gm opens violations channel
    player->hasViolationsChannelOpen = true;
    NetworkMessage newmsg;
    
    newmsg.AddByte(0xAE);
    newmsg.AddU16(0x0003);

    for(std::vector<Player*>::iterator it = g_game.openViolations.begin(); it != g_game.openViolations.end(); ++it) 
    {// use vector to get right order
        if (it != g_game.openViolations.end())
        if ((*it) && (*it)->hasOpenViolation) // its valid
        {
            newmsg.AddByte(0xAA);
            newmsg.AddU32(0);
            newmsg.AddString((*it)->getName());
            newmsg.AddU16(0); //level 
            newmsg.AddByte(SPEAK_CHANNEL_RV1);

            uint64_t secs = (OTSYS_TIME() - (*it)->violationTime)/1000;
            newmsg.AddU32((long)(secs));
            
            newmsg.AddString((*it)->violationReport);
        }
    }
    WriteBuffer(newmsg);

}

void Protocol80::sendNetworkMessage(NetworkMessage *msg)
{
	WriteBuffer(*msg);
}

#endif


protocol79.h (public)
Code:
PHP:
		#ifdef SDG_VIOLATIONS
	void sendNetworkMessage(NetworkMessage *msg);
    void addViolation(Player* reporter, std::string message); // player uses ctrl-r
    void removeViolation(std::string rname);    // remove open violation from stack
    void cancelViolation(std::string rname);    // player cancels violation/logsout
    void openViolation(NetworkMessage &msg);    // gm answers in violations
    void closeViolation(NetworkMessage &msg);   // gm closes report
    void speakToReporter(std::string rname, std::string message);
    void speakToCounsellor(std::string message);
    void updateViolationsChannel(NetworkMessage &update); // new/canceled/opened report
    virtual void sendViolationChannel(Player* gm);  // gm opens violations
    
    #endif

const80.h
speakclasses
Code:

#ifdef SDG_VIOLATIONS
	SPEAK_CHANNEL_RV1 	= 0x06,     // report violation
	SPEAK_CHANNEL_RV2 	= 0x07,     // answer report (couns/gm)
	SPEAK_CHANNEL_RV3 	= 0x08,     // reply from reportee
#endif

game.cpp
bool Game::playerSay
Code:

PHP:
#ifdef SDG_VIOLATIONS		
	case SPEAK_CHANNEL_RV1:
        return addViolation(player, text);
        break;
    case SPEAK_CHANNEL_RV2:
	     return speakToReporter(player, receiver, text);
	     break;
    case SPEAK_CHANNEL_RV3:
        return speakToCounsellor(player, text);
	    break;
#endif

at the bottom
Code:

PHP:
#ifdef SDG_VIOLATIONS
bool Game::addViolation(Player* player, std::string message)
{
    player->client->addViolation(player, message); 
    return true;
}

bool Game::speakToReporter(Player* player, std::string rname, std::string message)
{ 
     player->client->speakToReporter(rname, message);
     return true;
}

bool Game::speakToCounsellor(Player* player, std::string message)
{ 
    player->client->speakToCounsellor(message);
    return true;
}

#endif

game.h
public
Code:

PHP:
#ifdef SDG_VIOLATIONS
	std::vector<Player*> openViolations;
    bool addViolation(Player* player, std::string message); // player uses ctrl-r
    bool speakToReporter(Player* player, std::string rname, std::string message);
    bool speakToCounsellor(Player* player, std::string message);
    #endif

player.cpp
bottom
Code:

PHP:
#ifdef SDG_VIOLATIONS
void Player::sendNetworkMessage(NetworkMessage *msg)
{
     client->sendNetworkMessage(msg);
}
#endif

player.h
Code:

	#ifdef SDG_VIOLATIONS
    bool hasViolationsChannelOpen; // for updates of newly added/answered by other/cancelled
    bool hasOpenViolation;  // to cancel/close violation on logout etc.
    std::string violationName;  // reporter name or gm name, depends on side of convo
    uint64_t violationTime;     // time when reported
    std::string violationReport; // the report string
    void sendNetworkMessage(NetworkMessage *msg);
#endif

chat.cpp
Chat::Chat()
Code:

	#ifdef SDG_VIOLATIONS		
	newChannel = new ChatChannel(0x01, "GameMaster");
	if(newChannel)
		m_normalChannels[0x01] = newChannel;

	newChannel = new ChatChannel(0x02, "Counsellor");
	if(newChannel)
		m_normalChannels[0x02] = newChannel;
		
	newChannel = new ChatChannel(0x03, "Rule Violations");
	if(newChannel)
		m_normalChannels[0x03] = newChannel;
#endif

bool Chat::addUserToChannel
under
Quote:
if(!channel)
return false;
add
Code:

#ifdef SDG_VIOLATIONS
if ((channelId == 0x01 && player->getAccessLevel() < 3) // gm channel - edit to your gm access
||(channelId == 0x02 && player->getAccessLevel() < 2) // counsellor - edit access as needed
||(channelId == 0x03 && player->getAccessLevel() < 2))// violations - edit as needed
return false;
#endif[/PHP]

replace
Quote:
//TODO: Permisions for channels and checks
with
Code:

PHP:
#ifdef SDG_VIOLATIONS
        if (itn->first <= 0x03)
            if ((itn->first == 0x01 && player->getAccessLevel() < 3)  // gm channel
            || (itn->first == 0x02 && player->getAccessLevel() < 2)   // couns channel
            || (itn->first == 0x03 && player->getAccessLevel() < 2)   // violations
            ) continue;
#endif

Hope you get it to work :p
Comments please :D
 
Last edited:
are you kidding with credits to you? give credits to ispiro leecher
 
Last edited:
glad to see this code is still out there and useful :)
gratz to whoever fixed it to work after 7.7, i never felt like it ;D
friend recently got me back into ot, and was happy to stumble across an alredy fixed (mostly) copy

full source of my old 7.5 server is on sourceforge, under 'nuuberland-ots'

-El PeeKay
 
Back
Top