Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

[TuT] System Raportów CTRL+R Na Twój Serwer


Gość Maxikk

Rekomendowane odpowiedzi

Opublikowano

Witam w tym tutorialu pokażę wam jak zrobić system raportów na swój serwer czyli CTRL+R tak więc zaczynamy...

 

 

Otwieramy plik chat.cpp i nad tym kodem:

 

newChannel = new ChatChannel(0x04, "Game-Chat");
   if(newChannel)
       m_normalChannels[0x04] = newChannel;

 

dodajemy ten:

 

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

 

Następnie nad:

 

if(channel->addUser(player))
       return true;

 

Dodajemy:

 

#ifdef HUCZU_RRV
   if (player && channelId == 0x03 && player->access < 1)// kanal nie dostepny dla access ponizej 1
       return false;
#endif

 

Następnie Pod:

 

for(itn = m_normalChannels.begin(); itn != m_normalChannels.end(); ++itn){
       //TODO: Permisions for channels and checks
       ChatChannel *channel = itn->second;

 

Dodajemy:

 

#ifdef HUCZU_RRV
    if(itn->first == 0x03 && player && player->access < 1)   // nie wyswietli kanalu rule violations dla access 0 w liscie kanalow
          continue;
#endif

 

Zapisujemy i zamykamy następnie przechodzimy do const76.h i pod:

 

SPEAK_CHANNEL_Y        = 0x05,    //yellow

 

dodajemy:

 

#ifdef HUCZU_RRV
   SPEAK_CHANNEL_RV1     = 0x06,     // raport w kanale
   SPEAK_CHANNEL_RV2     = 0x07,     // odpowiedz gm
   SPEAK_CHANNEL_RV3     = 0x08,     // odpowiedz gracza
#endif

 

Zapisujemy i zamykamy następnie przechodzimy do game.cpp i pod:

 

if(player->eventAutoWalk)
           stopEvent(player->eventAutoWalk);

 

Dodajemy:

 

#ifdef HUCZU_RRV
       if(player->violationReport != "") // taki myk, gdy zmienna przechowuje wiad raportu
           player->cancelPlayerViolation(); // to nam zamknie raporty otwarte i nie otwarte.
#endif

 

Zapisujemy i zamykamy następnie przechodzimy do game.h i w public dodajemy:

 

#ifdef HUCZU_RRV
   std::vector<Player*> openViolations; //wektor przechowuje graczy ktorzy wyslali raport
#endif

 

Zapisujemy i zamykamy następnie przechodzimy do player.cpp i pod:

 

guildId = 0;

 

Dodaj:

 

#ifdef HUCZU_RRV
   bool hasViolationsChannelOpen = false; //sprawdza czy gm otwarty kanal ma
   bool hasOpenViolation = false; //czy gracz wyslal raport
   std::string violationName = ""; //nazwa gma co otworzyl raport
   unsigned long long violationTime = 0; //czas
   std::string violationReport = ""; //tresc raportu
#endif

 

Na końcu pliku dodaj:

 

#ifdef HUCZU_RRV
void Player::cancelPlayerViolation()
{
   client->cancelViolation(this->getName());
}
#endif

 

Zapisujemy i zamykamy następnie przechodzimy do pliku player.h i w public dodajemy:

 

#ifdef HUCZU_RRV
   bool hasViolationsChannelOpen;  
   bool hasOpenViolation;  
   std::string violationName;  
   unsigned long long violationTime;    
   std::string violationReport;
   void cancelPlayerViolation();
#endif

 

Zapisujemy i zamykamy następnie przechodzimy do protocol.h i pod tym:

 

virtual void RemoveItemContainer(NetworkMessage &msg,unsigned char cid,unsigned short slot) = 0;

 

Dodajemy:

 

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

 

Zamykamy i zapisujemy plik a następnie zabieramy się za ostatni plik protocol76.cpp pod:

 

case 0x96:  // say something
       parseSay(msg);
       break;

 

Dodajemy:

 

#ifdef HUCZU_RRV
   case 0x9B: // wysyla raport
       openViolation(msg);
       break;

   case 0x9C: // zamyka gm raport
       closeViolation(msg);
       break;

   case 0x9D: // anuluje raport
       cancelViolation(player->getName());
       break;
#endif

 

Następnie pod:

 

OTSYS_THREAD_LOCK_CLASS lockClass(game->gameLock, "Protocol76::parseOpenChannel()");

 

Dodajemy:

 

#ifdef HUCZU_RRV
   if (channelId == 0x03 && player && player->access >= 1) // kanal dostepny tylko dla access >= 1
   {
       sendViolationChannel(player);
       return;
   }else{
#endif

 

Kilka linijek niżej pod:

 

if(g_chat.addUserToChannel(player, channelId))
       sendChannel(channelId, g_chat.getChannelName(player, channelId));

 

Dodajemy:

 

#ifdef HUCZU_RRV
   } // domykamy :P
#endif

 

Następnie pod:

 

OTSYS_THREAD_LOCK_CLASS lockClass(game->gameLock, "Protocol76::parseCloseChannel()");

 

Dodajemy:

 

#ifdef HUCZU_RRV
   if (player && channelId == 0x03)
   player->hasViolationsChannelOpen = false;
   else
#endif

 

Następnie pod:

 

if(type == SPEAK_PRIVATE ||

 

Dodajemy:

 

#ifdef HUCZU_RRV
      type == SPEAK_CHANNEL_RV2 ||
#endif

 

Następnie pod:

 

case SPEAK_BROADCAST:
       game->creatureBroadcastMessage(player, text);
       break;

 

Dodajemy:

 

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

 

Na końcu pliku umieść:

 

#ifdef HUCZU_RRV
void Protocol76::addViolation(Player* reporter, std::string message)
{// dodajemy raport
   OTSYS_THREAD_LOCK_CLASS lockClass(game->gameLock, "Protocol76::addViolation()");
   if(reporter){
   reporter->violationTime = OTSYS_TIME();
   reporter->violationReport = message;
   reporter->hasOpenViolation = true;

   game->openViolations.push_back(reporter);

   NetworkMessage msg;
   msg.AddByte(0xAA);
   msg.AddString(reporter->getName());
   msg.AddByte(SPEAK_CHANNEL_RV1);
   msg.AddU32(0x00000000);
   msg.AddString(reporter->violationReport);
   updateViolationsChannel(msg);
   }
}

void Protocol76::removeViolation(std::string rname)
{ // usuwamy raport
   OTSYS_THREAD_LOCK_CLASS lockClass(game->gameLock, "Protocol76::removeViolation()");
   NetworkMessage msg;

       msg.AddByte(0xAF);
       msg.AddString(rname);
       updateViolationsChannel(msg);

   for(std::vector<Player*>::iterator it = game->openViolations.begin(); it != game->openViolations.end(); ++it)
   { // szukamy gracza w wektorze i dokonujemy zmian
       if ((*it) && (*it)->getName() == rname) // zlapany!
       {
               (*it)->hasOpenViolation = false;
               (*it)->violationName = "";
               (*it)->violationTime = 0;
               (*it)->violationReport = "";
               game->openViolations.erase(it);
               return; // konczymy
       }
   }
}

void Protocol76::cancelViolation(std::string rname)
{// anulujemy raport
   OTSYS_THREAD_LOCK_CLASS lockClass(game->gameLock, "Protocol76::cancelViolation()");
   NetworkMessage msg;
   Player* gm = game->getPlayerByName(player->violationName);
   if (gm)
   { // znalazl gm

       msg.AddByte(0xB0); // blokuje kanal
       msg.AddString(rname);
       gm->sendNetworkMessage(&msg);

       gm->violationName = "";
       player->violationName = "";
   }
   removeViolation(rname);

}

void Protocol76::openViolation(NetworkMessage &msg)
{ // gm odpowiada i otwiera raport
   OTSYS_THREAD_LOCK_CLASS lockClass(game->gameLock, "Protocol76::openViolation()");
   std::string rname = msg.GetString();
   NetworkMessage newmsg;

   Player* reporter = game->getPlayerByName(rname);
   if (reporter)
   {
       removeViolation(rname);

       reporter->violationName = player->getName();
       player->violationName = rname;
   }

}

void Protocol76::closeViolation(NetworkMessage &msg)
{ // zamykamy raport
   OTSYS_THREAD_LOCK_CLASS lockClass(game->gameLock, "Protocol76::closeViolation()");
   std::string rname = msg.GetString();
   NetworkMessage newmsg;

   Player* reporter = game->getPlayerByName(rname);

   if (reporter)
   {
       if (reporter->hasOpenViolation)
         removeViolation(rname);

       newmsg.AddByte(0xB1);  
       reporter->sendNetworkMessage(&newmsg);

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

}

void Protocol76::speakToReporter(std::string rname, std::string message)
{ // gm pisze do raportujacego
   OTSYS_THREAD_LOCK_CLASS lockClass(game->gameLock, "Protocol76::speakToReporter()");
   NetworkMessage newmsg;
   Player* reporter = game->getPlayerByName(rname);

   if (reporter)
   {
       newmsg.AddByte(0xAA);
       //newmsg.AddU32(0);
       newmsg.AddString("Counsellor");
       newmsg.AddByte(SPEAK_CHANNEL_RV2);
       newmsg.AddString(message);
       reporter->sendNetworkMessage(&newmsg);
       newmsg.Reset();
       newmsg.AddByte(0xB4);
       newmsg.AddByte(MSG_SMALLINFO);
       std::stringstream ss;
       ss << "Message sent to " << reporter->getName() << ".";
       newmsg.AddString(ss.str());
       WriteBuffer(newmsg);
   }

}

void Protocol76::speakToCounsellor(std::string message)
{ // raportujacy pisze do gm
   OTSYS_THREAD_LOCK_CLASS lockClass(game->gameLock, "Protocol76::speakToCounsellor()");
   NetworkMessage newmsg;
   Player* gm = game->getPlayerByName(player->violationName);

   if (gm)
   {
       newmsg.AddByte(0xAA);
       newmsg.AddString(player->getName());
       newmsg.AddByte(SPEAK_CHANNEL_RV3);
       newmsg.AddString(message.c_str());
       gm->sendNetworkMessage(&newmsg);
       newmsg.Reset();
       newmsg.AddByte(0xB4);
       newmsg.AddByte(MSG_SMALLINFO);
       newmsg.AddString("Message sent to Counsellor.");
       WriteBuffer(newmsg);
   }

}

void Protocol76::updateViolationsChannel(NetworkMessage &update)
{// aktualizacja
   for(AutoList<Player>::listiterator it = Player::listPlayer.list.begin(); it != Player::listPlayer.list.end(); ++it)
       if ((*it).second->hasViolationsChannelOpen)
           (*it).second->sendNetworkMessage(&update);

}

void Protocol76::sendViolationChannel(Player* gm)
{ // gm otwiera kanal raportow
   player->hasViolationsChannelOpen = true;
   NetworkMessage newmsg;

   newmsg.AddByte(0xAE);
   newmsg.AddU16(0x0003);

   for(std::vector<Player*>::iterator it = game->openViolations.begin(); it != game->openViolations.end(); ++it)
   {// szuka zgloszen
       if (it != game->openViolations.end())
       if ((*it) && (*it)->hasOpenViolation) // znalazl!
       {
           newmsg.AddByte(0xAA);
           newmsg.AddString((*it)->getName());
           newmsg.AddByte(SPEAK_CHANNEL_RV1);

           unsigned long long secs = (OTSYS_TIME() - (*it)->violationTime)/1000;
           newmsg.AddU32((long)(secs));

           newmsg.AddString((*it)->violationReport);
       }
   }
   WriteBuffer(newmsg);

}
#endif

 

Jeszcze w pliku protocol76.h umieść pod:

 

virtual void sendIcons(int icons);

 

To:

 

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

 

System Napisał Huczu

Udostępnił Maxikk

Jeśli chcesz dodać odpowiedź, zaloguj się lub zarejestruj nowe konto

Jedynie zarejestrowani użytkownicy mogą komentować zawartość tej strony.

Zarejestruj nowe konto

Załóż nowe konto. To bardzo proste!

Zarejestruj się

Zaloguj się

Zaloguj się poniżej.

Zaloguj się
×
×
  • Dodaj nową pozycję...