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] Parcel System na Twój Serwer


Gość Maxikk

Rekomendowane odpowiedzi

Opublikowano

Nie masz na serwerze parcel system? chcesz aby twoi gracze bez problemu mogli wysyłać pomiędzy sobą itemki? ten tutek jest dla ciebie!! tak więc zaczynamy!!

 

 

Otwieramy plik player.h i szukamy tych 2 linijek:

 

time_t lastlogin;
time_t lastLoginSaved;

 

Przenosimy te linijki pod Public... Następnie zapisujemy i zamykamy plik oraz przechodzimy do protocol76.cpp i tu na sam początek pliku dodajemy:

 

#include "ioplayer.h"

 

Następnie szukamy:

 

void Protocol76::parseTextWindow(NetworkMessage &msg)
{
   unsigned long id = msg.GetU32();
   std::string new_text = msg.GetString();
   if(readItem && windowTextID == id){    
       sendTextMessage(MSG_SMALLINFO, "Write not working yet.");
       //move to Game, and use gameLock
       /*//TODO: check that the item is in
       //an accesible place for the player
       unsigned short itemid = readItem->getID();
       readItem->setText(new_text);
       if(readItem->getID() != id){
       //TODO:update the item in the clients.
       //Can be done when find a method to get
       // items position its pointer.
   }*/
       readItem->releaseThing();
       readItem = NULL;
   }
}

 

i zastępujemy tym:

 

void Protocol76::parseTextWindow(NetworkMessage &msg)
{
unsigned long id = msg.GetU32();
std::string new_text = msg.GetString();
if(readItem && windowTextID == id)
{
readItem->setText(new_text);
readItem->releaseThing();
readItem = NULL;
}
}

 

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

 

if(from_x == to_x && from_y == to_y && from_z == to_z)
return;

 

dodajemy:

 

if(to_x != 0xFFFF && (itemid == ITEM_PARCEL || itemid == ITEM_LETTER))
{
Tile* t = game->getTile(to_x, to_y, to_z);
if(t && (t->hasItem(ITEM_MAILBOX1) || t->hasItem(ITEM_MAILBOX2)))
{
Item* parcel = dynamic_cast<Item*>(game->getThing(Position(from_x, from_y, from_z), from_stack, player));
if(parcel)
{
bool canSend = true;
bool foundLabel = false;
std::string receiver;
unsigned int depotid;
Container* parcel2 = dynamic_cast<Container*>(parcel);
if(parcel2 && itemid == ITEM_PARCEL)
{
for(int x = 0; x < parcel2->size(); x++)
{
Item* label = dynamic_cast<Item*>(parcel2->getItem(x));
if(label && label->getID() == ITEM_LABEL)
{
foundLabel = true;
std::string text = label->getText();
std::istringstream iss(text, std::istringstream::in);
int i = 0;
std::string line[2];
while(std::getline(iss, text,'\n'))
{
line[i] = text;
i++;
if(i == 2)
break;
}
receiver = line[0];
std::transform(line[1].begin(), line[1].end(), line[1].begin(), (int(*)(int))tolower);
if(line[1] == "city")
depotid = 1;
else if(line[1] == "city") // add as much as you want
depotid = 2;
else
canSend = false;
if(!game->isPlayer(receiver))
canSend = false;
if(canSend)
break;
}
}
}
else if(itemid == ITEM_LETTER)
{
foundLabel = true;
std::string text = parcel->getText();
std::istringstream iss(text, std::istringstream::in);
int i = 0;
std::string line[2];
while(std::getline(iss, text,'\n'))
{
line[i] = text;
i++;
if(i == 2)
break;
}
receiver = line[0];
std::transform(line[1].begin(), line[1].end(), line[1].begin(), (int(*)(int))tolower);
if(line[1] == "city")
depotid = 1;
else if(line[1] == "city") // add as much as you want
depotid = 2;
else
canSend = false;
if(!game->isPlayer(receiver))
canSend = false;
}
if(canSend && foundLabel)
{
game->removeThing(player,Position(from_x, from_y, from_z), parcel, true);
Player* player = game->getPlayerByName(receiver);
if(player)
{
parcel->setID((itemid == ITEM_LETTER?ITEM_STLETTER:ITEM_STPARCEL));
Container* depot = player->getDepot(depotid);
if(depot)
depot->addItem(parcel);
std::vector<unsigned char> containerlist;
containerLayout::const_iterator cit;
for(cit = player->getContainers(); cit != player->getEndContainer(); ++cit)
{
Container* c = cit->second;
if(c == depot)
{
player->sendTextMessage(MSG_ADVANCE, "Dostales nowa wiadomosc.");
player->onItemAddContainer(depot, parcel);
break;
}
if(c->getParent() == depot)
{
player->sendTextMessage(MSG_ADVANCE, "Dostales nowa wiadomosc.");
break;
}
}
}
else
{
Protocol76* prot = new Protocol76(0);
player = new Player(receiver, prot);
parcel->setID((itemid == ITEM_LETTER?ITEM_STLETTER:ITEM_STPARCEL));
IOPlayer::instance()->loadPlayer(player, receiver);
Container* depot = player->getDepot(depotid);
if(depot)
depot->addItem(parcel);
player->lastlogin = player->lastLoginSaved;
IOPlayer::instance()->savePlayer(player);
delete player;
}
return;
}
}
}
}

 

Następnie w game.cpp na samej górze pliku dodajemy:

 

#include <iostream>
#include <fstream>

 

i na końcu pliku dodajemy:

 

bool Game::isPlayer(const std::string name)
{
OTSYS_THREAD_LOCK_CLASS lockClass(gameLock, "Game::isPlayer()");
std::stringstream s;
s << "data/players/" << name << ".xml";
ifstream namefile(s.str().c_str());
if(namefile.is_open())
{
namefile.close();
return true;
}
return false;
}

 

Zapisujemy i zamykamy plik następnie przechodzimy do tile.cpp i na samym końcu dodajemy:

 

bool Tile::hasItem(unsigned long id) const
{  
ItemVector::const_iterator iit;
for(iit = topItems.begin(); iit != topItems.end(); ++iit)
{
if((*iit)->getID() == id)
return true;
}
for(iit = downItems.begin(); iit != downItems.end(); ++iit)
{
if((*iit)->getID() == id)
return true;
}
return false;
}

 

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

 

void setPz();

 

Dodajemy:

 

bool hasItem(unsigned long id) const;

 

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

 

[b]public:[/b]
   Game();
 ~Game();

 

Dodajemy:

 

bool isPlayer(const std::string name);

 

 

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

 

ITEM_CHEESE            = 2696,

 

Dodajemy:

 

ITEM_PARCEL = 2595,
ITEM_STPARCEL = 2596,
ITEM_LETTER = 2597,
ITEM_STLETTER = 2598,
ITEM_MAILBOX1 = 2593,
ITEM_MAILBOX2 = 2334,
ITEM_LABEL = 2599,

 

Kompilujemy silnik i cieszymy się Parcel Systemem:)

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ę...