C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 30th, 2006, 01:19 PM
Java Robin XTF Java Robin XTF is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: New York City
Posts: 25 Java Robin XTF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 18 sec
Reputation Power: 0
C++ Need help adding a few functions/features..

I need to add functions that allow a person to log onto my server and walk right, left, up, down, diagonal up, diagonal down, ect.
I need players to be able to turn left right up and down.
I need players to be able to talk so text appears in default and in private messaging...

Download source code here:
Source Codes
account.cpp:
Code:
#include "Account.h"

#include "definitions.h"


#include <libxml/xmlmemory.h>
#include <libxml/parser.h>

#include <algorithm>
#include <iostream>


Account::Account()
{
                                
}

Account::~Account()
{
                 
}

bool Account::openAccount(const string &account, const string &givenpassword)
{
  string filename = "data/accounts/" + account + ".xml";
  std::transform(filename.begin(), filename.end(), filename.begin(), (int(*)(int))tolower);

    xmlDocPtr doc = xmlParseFile(filename.c_str());

  if (doc)
  {
    xmlNodePtr root, p, tmp;
	  root = xmlDocGetRootElement(doc);

	  if (xmlStrcmp(root->name,(const xmlChar*) "account"))
    {
  	  return false;
	  }

	  p = root->children;

	  // perhaps verify name
    const char* pwd = (const char*)xmlGetProp(root, (const xmlChar *)"pass");

    if ((pwd == NULL) || (givenpassword != pwd)) {
      xmlFreeDoc(doc);
      return false;
    }

      
	  password  = pwd;

	  acctype   = atoi((const char*)xmlGetProp(root, (xmlChar*)"type"));
	  premDays  = atoi((const char*)xmlGetProp(root, (xmlChar*)"premDays"));

	  
    // now load in characters.
	  while (p)
    {
	    const char* str = (char*)p->name;
	  
	    if (strcmp(str, "characters") == 0)
      {
			  tmp = p->children;
			  while(tmp)
        {
				  const char* temp_a = (const char*)xmlGetProp(tmp, (xmlChar*)"name");

          if ((strcmp((const char*)tmp->name, "character") == 0) && (temp_a != NULL))
				    charList.push_back(temp_a);

				  tmp = tmp->next;
			  }
		  }
	    p = p->next;
	  }
	  xmlFreeDoc(doc);

    // Organize the char list.
    charList.sort();

    return true;
  }

  return false;
}

Account.h
Code:
#ifndef __ACCOUNT_H__
#define __ACCOUNT_H__

#include <string>
#include <list>

using namespace std;


class Account
{
public:
Account();
~Account();

unsigned long accnumber;
int acctype;     // ?
int premDays;    // Premium days
std::string password;       
std::list<std::string> charList;
bool openAccount(const string &account, const string &givenpassword);
};

#endif

Reply With Quote
  #2  
Old September 30th, 2006, 08:36 PM
Java Robin XTF Java Robin XTF is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: New York City
Posts: 25 Java Robin XTF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 18 sec
Reputation Power: 0
Bump-- So someone can see this..
Please if you have no idea how to add the features at least give it a try.. I don't want to waste loads of time(like last time) figuring out how to add optimized codes =/
Maybe if people could add bits and pieces it would be easier..
Definitions.h
Code:

#ifndef __DEFINITIONS_H__
#define __DEFINITIONS_H__

#define NETWORKMESSAGE_MAXSIZE 16768
#define OTSYS_CREATE_THREAD(a, b) _beginthread(a, 0, b)

#define OTSYS_THREAD_LOCKVAR HANDLE
#define OTSYS_THREAD_LOCKVARINIT(a)    a = CreateMutex(NULL, FALSE, NULL);
#define OTSYS_THREAD_LOCKVARRELEASE(a) CloseHandle(a);

#define OBSOLETE

#ifndef NULL
#define NULL 0
#endif

#define Min(a,b) ( (a < b) ? a : b )
#define Max(a,b) ( (a > b) ? a : b )
#define Abs(a) ( (a >= 0) ? a : -a )

#ifdef XML_GCC_FREE
	#define xmlFreeOTSERV(s)	free(s)
#else
	#define xmlFreeOTSERV(s)	xmlFree(s)
#endif

typedef char TCByte, *String;
typedef bool Boolean;
typedef unsigned char Byte;
typedef unsigned short UInt16;
typedef unsigned int UInt32;
typedef unsigned long long UInt64;
#endif


Enums.h
Code:
#ifndef __ENUMS_H__
#define __ENUMS_H__


#ifndef _SLOT_T_
#define _SLOT_T_

enum Slot_t
{
    IS_NONE     = 0x00,

    IS_HEAD     = 0x01,
    IS_NECKLACE = 0x02,
    IS_BACKPACK = 0x03,
    IS_ARMOR    = 0x04,
    IS_RIGHT    = 0x05,
    IS_LEFT     = 0x06,
    IS_LEGS     = 0x07,
    IS_FEET     = 0x08,
    IS_RING     = 0x09,
    IS_AMMO     = 0x0A
};

#endif

enum Skill_t
{
    PS_NONE      = 0xFF,

    PS_FIST      = 0x01,
    PS_CLUB      = 0x02,
    PS_SWORD     = 0x03,
    PS_AXE       = 0x04,
    PS_DISTANCE  = 0x05,
    PS_SHIELDING = 0x06,
    PS_FISHING   = 0x07
};

enum Direction_t
{
    NORTH      = 0x00,
	EAST       = 0x01,
	SOUTH      = 0x02,
	WEST       = 0x03,
	NORTH_EAST = 0x05,
	SOUTH_EAST = 0x06,
	SOUTH_WEST = 0x07,
	NORTH_WEST = 0x08
};

enum Access_t /* Creature Access */
{
    CA_NONE              = 0x00,
    CA_TUTOR             = 0x01,
    CA_COUNSELLOR        = 0x02,
    CA_GAMEMASTER        = 0x03,
    CA_GOD               = 0x04
};

enum Skull_t
{
    SC_NONE   = 0x00,

    SC_YELLOW = 0x01,
    SC_GREEN  = 0x02,
    SC_WHITE  = 0x03,
    SC_RED    = 0x04
};

enum Shield_t
{
    ST_NONE    = 0x00,

    ST_UNKNOWN = 0x01, /* Some sort of crazy strange invisible shield */
    ST_GUEST   = 0x02, /* Invited but haven't joined yet */
    ST_MEMBER  = 0x03, /* Invited and accepted the invitation */
    ST_LEADER  = 0x04  /* The one that invites people */
};

enum Race_t /* Creature Race */
{
    CR_LIVING = 1, //Humans, etc.
    CR_UNDEAD = 2, //Skels, Banshee, etc.
    CR_POISON = 3, //Giant Spider, Poison Spider, etc.
    CR_FIRE   = 4  //Fire elemental, Demon, etc.
};

enum Outfit_t /* Outfits */
{
    OF_NONE                = 0x00,

    OF_INVISIBLE           = 0x01,    OF_ORC_WARLORD         = 0x02,    OF_WAR_WOLF          = 0x03,  
    OF_ORC_RIDER           = 0x04,    OF_ORC                 = 0x05,    OF_ORC_SHAMAN        = 0x06,  
    OF_ORC_WARRIOR         = 0x07,    OF_ORC_BERSERKER       = 0x08,    OF_NECROMANCER       = 0x09,  
    OF_YELLOW_BUTTERFLY    = 0x0A,    OF_BLACK_SHEEP         = 0x0D,    OF_SHEEP             = 0x0E,
    OF_TROLL               = 0x0F,    OF_BEAR                = 0x10,    OF_BEHOLDER          = 0x11,
    OF_GHOUL               = 0x12,    OF_SLIME               = 0x13,    OF_RAT               = 0x15,  
    OF_CYCLOPS             = 0x16,    OF_MINOTAUR_MAGE       = 0x17,    OF_MINOTAUR_ARCHER   = 0x18,  
    OF_MINOTAUR            = 0x19,    OF_ROTWORM             = 0x1A,    OF_WOLF              = 0x1B,  
    OF_SNAKE               = 0x1C,    OF_MINOTAUR_GUARD      = 0x1D,    OF_SPIDER            = 0x1E,  
    OF_DEER                = 0x1F,    OF_DOG                 = 0x20,    OF_SKELETON          = 0x21,  
    OF_DRAGON              = 0x22,    OF_DEMON               = 0x23,    OF_POISON_SPIDER     = 0x24,  
    OF_DEMON_SKELETON      = 0x25,    OF_GIANT_SPIDER        = 0x26,    OF_DRAGON_LORD       = 0x27,  
    OF_FIRE_DEVIL          = 0x28,    OF_LION                = 0x29,    OF_POLAR_BEAR        = 0x2A,  
    OF_SCORPION            = 0x2B,    OF_WASP                = 0x2C,    OF_BUG               = 0x2D,  
    OF_GHOST               = 0x30,    OF_FIRE_ELEMENTAL      = 0x31,    OF_ORC_SPEARMAN      = 0x32,
    OF_GREEN_DJINN         = 0x33,    OF_WINTER_WOLF         = 0x34,    OF_FROST_TROLL       = 0x35,
    OF_WITCH               = 0x36,    OF_BEHEMOTH            = 0x37,    OF_CAVE_RAT          = 0x38,
    OF_MONK                = 0x39,    OF_PRIESTESS           = 0x3A,    OF_ORC_LEADER        = 0x3B,
    OF_PIG                 = 0x3C,    OF_GOBLIN              = 0x3D,    OF_ELF               = 0x3E,
    OF_ELF_ARCANIST        = 0x3F,    OF_ELF_SCOUT           = 0x40,    OF_MUMMY             = 0x41, 
    OF_DWARF_GEOMANCER     = 0x42,    OF_STONE_GOLEM         = 0x43,    OF_VAMPIRE           = 0x44,
    OF_DWARF               = 0x45,    OF_DWARF_GUARD         = 0x46,    OF_DWARF_SOLDIER     = 0x47, 
    OF_HERO                = 0x49,    OF_RABBIT              = 0x4A,    OF_GAMEMASTER        = 0x4B,  
    OF_SWAMP_TROLL         = 0x4C,    OF_BANSHEE             = 0x4E,    OF_ANCIENT_SCARAB    = 0x4F,
    OF_BLUE_DJINN          = 0x50,    OF_COBRA               = 0x51,    OF_LARVA             = 0x52,
    OF_SCARAB              = 0x53,    OF_PHARAOH1            = 0x54,    OF_PHARAOH2          = 0x55,
    OF_PHARAOH3            = 0x56,    OF_PHARAOH_DRESSED1    = 0x57,    OF_PHARAOH_DRESSED2  = 0x58,
    OF_PHARAOH4            = 0x59,    OF_PHARAOH5            = 0x5A,    OF_PHARAOH_DRESSED3  = 0x5B,
    OF_MIMIC               = 0x5C,    OF_HYAENA              = 0x5E,    OF_GARGOYLE          = 0x5F, 
    OF_LICH                = 0x63,    OF_CRYPT_SHAMBLER      = 0x64,    OF_BONE_BEAST        = 0x65,
    OF_DEATHSLICER         = 0x66,    OF_EFREET              = 0x67,    OF_MARID             = 0x68,   
    OF_BADGER              = 0x69,    OF_SKUNK               = 0x6A,    OF_DEMONILLUSION     = 0x6B,
    OF_ELDER_BEHOLDER      = 0x6C,    OF_GAZER               = 0x6D,    OF_YETI              = 0x6E,
    OF_CHICKEN             = 0x6F,    OF_CRAB                = 0x70,    OF_LIZARD_TEMPLAR    = 0x71,
    OF_LIZARD_SENTINEL     = 0x72,    OF_LIZARD_SNAKECHARMER = 0x73,    OF_KONGRA            = 0x74,
    OF_MERLKIN             = 0x75,    OF_SIBANG              = 0x76,    OF_CROCODILE         = 0x77,
    OF_CARNIPHILA          = 0x78,    OF_HYDRA               = 0x79,    OF_BAT               = 0x7A,
    OF_PANDA               = 0x7B,    OF_CENTIPEDE           = 0x7C,    OF_TIGER             = 0x7D,

    /* Humans */
    OF_WOMANUGLY           = 0x7E,    OF_MANUGLY             = 0x7F,    OF_MAN1              = 0x80,
    OF_MAN2                = 0x81,    OF_MAN3                = 0x82,    OF_MAN4              = 0x83,
    OF_MAN5_PREM           = 0x84,    OF_MAN6_PREM           = 0x85,    OF_MAN7_PREM         = 0x86,
    OF_WOMAN1              = 0x88,    OF_WOMAN2              = 0x89,    OF_WOMAN3            = 0x8A,
    OF_WOMAN4              = 0x8B,    OF_WOMAN5_PREM         = 0x8C,
    OF_WOMAN6_PREM         = 0x8D,    OF_WOMAN7_PREM         = 0x8E,

    OF_ELF_CHANGEABLE      = 0x90,    OF_DWARF_CHANGEABLE    = 0xA0,

    /* Boss Monsters */
    OF_ORSHABAAL           = 0xC9,    OF_GENERAL_MURIUS      = 0xCA,    OF_DHARALION         = 0xCB,
    OF_DEMODRAS            = 0xCC,    OF_GRORLAM             = 0xCD,    OF_FERNFANG          = 0xCE,
    OF_THE_HORNED_FOX      = 0xCF,    OF_THE_OLD_WIDOW       = 0xD0,    OF_NECROPHARUS       = 0xD1,
    OF_THE_EVIL_EYE        = 0xD2,

    OF_ELEPHANT            = 0xD3,    OF_FLAMINGO            = 0xD4,    OF_PINK_BUTTERFLY    = 0xD5,
    OF_DWORC_VOODOOMASTER  = 0xD6,    OF_DWORC_FLESHHUNTER   = 0xD7,    OF_DWORC_VENOMSNIPER = 0xD8,
    OF_PARROT              = 0xD9,    OF_TERROR_BIRD         = 0xDA,    OF_TARANTULA         = 0xDB,
    OF_SERPENT_SPAWN       = 0xDC,    OF_SPIT_NETTLE         = 0xDD,    OF_DARK_MONK         = 0xE1,
    OF_BLUE_BUTTERFLY      = 0xE3,    OF_RED_BUTTERFLY       = 0xE4
};

enum MagicEffect_t
{
    ME_NONE = 0x00,

    ME_RED_HIT       = 0x01,
    ME_BLUE_RING     = 0x02,
    ME_SMOKE         = 0x03,
    ME_YELLOW_HIT    = 0x04,
    ME_EXPLOSION     = 0x05,
    ME_EXPLOSION_HIT = 0x06,
    ME_FIRE          = 0x07,
    ME_POISON_GREEN  = 0x08,
    ME_POISON_YELLOW = 0x09,
    ME_HIT_AREA      = 0x0A,
    ME_BLUE_BUBBLE   = 0x0B,
    ME_ENERGY_DAMAGE = 0x0C,
    ME_SHINE_BLUE    = 0x0D,
    ME_SHINE_RED     = 0x0E,
    ME_SHINE_GREEN   = 0x0F,
    ME_FIRE_HIT      = 0x10,
    ME_POISON        = 0x11,
    ME_BLACK_BUBBLE  = 0x12,
    ME_MUSIC_GREEN   = 0x13,
    ME_MUSIC_RED     = 0x14,
    ME_MUSIC_YELLOW  = 0x16,
    ME_MUSIC_PURPLE  = 0x17,
    ME_MUSIC_BLUE    = 0x18,
    ME_MUSIC_WHITE   = 0x19
};

#endif

Reply With Quote
  #3  
Old October 1st, 2006, 02:13 AM
Java Robin XTF Java Robin XTF is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: New York City
Posts: 25 Java Robin XTF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 18 sec
Reputation Power: 0
Bump again.. Could someone help me out?
Must I do everything myself, :'(
Game.cpp:
Code:
#include "Game.h"
#include "Tile.h"
#include "Tools.h"
#include "Definitions.h"
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>

#include <algorithm>
#include <iostream>



Tile* Tiles[128][128][16];

Game::~Game ( void )
{

    for ( int X = 0; X < 128; ++X )
    {
        for ( int Y = 0; Y < 128; ++Y )
        {
            for ( int Z = 0; Z < 16; ++Z )
            {
                delete Tiles[X][Y][Z];
            }
        }
    }
}

void Game::Create ( void ) /* Allocates Tiles */
{

    for ( int X = 0; X < 128; ++X )
    {
        for ( int Y = 0; Y < 128; ++Y )
        {
            Tiles[X][Y][7] = new Tile ( 0x66, X, Y, 7 );
        }
    }

    for ( int X = 30; X < 34; ++X )
    {
        for ( int Y = 30; Y < 34; ++Y )
        {
            Tiles[X][Y][6] = new Tile( 0x68, X, Y, 6 );
        }
    }

    for ( int X = 30; X < 34; ++X )
    {
        for ( int Y = 30; Y < 34; ++Y )
        {
            Tiles[X][Y][5] = new Tile ( 0x67, X, Y, 5 );
        }
    }
}

bool Game::LoadMapXml(std::string filename)
{
	xmlDocPtr doc = xmlParseFile(filename.c_str());

	if(doc){
		xmlNodePtr root, spawnNode;		
		root = xmlDocGetRootElement(doc);
/*
    for ( int X = 0; X < 128; ++X )
    {
        for ( int Y = 0; Y < 128; ++Y )
        {
            Tiles[X][Y][7] = new Tile ( 100, X, Y, 7 );
        }
    }
*/

		if(xmlStrcmp(root->name,(const xmlChar*)"tiles") != 0){
			xmlFreeDoc(doc);
			return false;
		}
        int x;
        int y;
        int z;
        int itemId;
		int intValue;
		std::string strValue;

		spawnNode = root->children;
		while(spawnNode){
			if(xmlStrcmp(spawnNode->name, (const xmlChar*)"tile") == 0){

				if(readXMLInteger(spawnNode, "x", intValue)){
					x = intValue;
					cout << "\n x =" <<x <<"\t";
				}				
				else{
					xmlFreeDoc(doc);
					return false;
				}

				if(readXMLInteger(spawnNode, "y", intValue)){
					y = intValue;
					cout << "y=" <<y<<"\t";
				}
				else{
					xmlFreeDoc(doc);
					return false;
				}

				if(readXMLInteger(spawnNode, "z", intValue)){
					z = intValue;
					cout << "z=" <<z<<"\t";
				}
				else{
					xmlFreeDoc(doc);
					return false;
				}

				if(readXMLInteger(spawnNode, "itemid", intValue)){
					itemId = intValue;
					cout << "itemid=" <<itemId<<"\t";
				}
				else{
					xmlFreeDoc(doc);
					return false;
				}
                if(x == 0 || y == 0 || itemId == 0){
                cout << "\nsorry not possible creating NULL id\n";
                return false;
                }
                Tiles[x][y][z] = new Tile( itemId, x, y, z );
                cout << "\nadded tiles";

				xmlNodePtr tmpNode = spawnNode->children;
				while(tmpNode){
					if(xmlStrcmp(tmpNode->name, (const xmlChar*)"monster") == 0){

						if(readXMLString(tmpNode, "name", strValue)){
							//name = strValue;
						}
						else{
							tmpNode = tmpNode->next;
							continue;
						}

						if(readXMLInteger(tmpNode, "direction", intValue)){
							//rawdir = intValue;
						}

						if(readXMLInteger(tmpNode, "x", intValue)){
							//x = intValue;
						}
						else{
							tmpNode = tmpNode->next;
							continue;
						}

						if(readXMLInteger(tmpNode, "y", intValue)){
						//	y = intValue;
						}
						else{
							tmpNode = tmpNode->next;
							continue;
						}

						if(readXMLInteger(tmpNode, "spawntime", intValue)){
						//	spawntime = intValue;
						}
						else{
							tmpNode = tmpNode->next;
							continue;
						}
					}
					else if(xmlStrcmp(tmpNode->name, (const xmlChar*)"npc") == 0){

						if(readXMLString(tmpNode, "name", strValue)){
						//	name = strValue;
						}
						else{
							tmpNode = tmpNode->next;
							continue;
						}
						
						if(readXMLInteger(tmpNode, "direction", intValue)){
						//	rawdir = intValue;
						}

						if(readXMLInteger(tmpNode, "x", intValue)){
						//	x = intValue;
						}
						else{
							tmpNode = tmpNode->next;
							continue;
						}

						if(readXMLInteger(tmpNode, "y", intValue)){
						//	y = intValue;
						}
						else{
							tmpNode = tmpNode->next;
							continue;
						}

					}

					tmpNode = tmpNode->next;
				}
			}

			spawnNode = spawnNode->next;
		}

		xmlFreeDoc(doc);
		return true;
	}

	return false;
}

Tile* Game::GetTile ( UInt16 X, UInt16 Y, Byte Z )
{
    Tile* Result = Tiles[X][Y][Z];

    return Result;
}

Tile* Game::GetTile ( Position_t& Position )
{
    Tile* Result = Tiles[Position.X][Position.Y][Position.Z];

    return Result;
}

SpectatorList Game::GetSpectatorList ( Position_t& Position )
{
    SpectatorList List;
    SpectatorList::iterator LPCreature;

    int StartX = (Position.X - 8), EndX = (Position.X + 9);
    int StartY = (Position.Y - 6), EndY = (Position.Y + 7);

    int BaseX, BaseY;


        for ( BaseX = StartX; BaseX <= EndX; ++BaseX )
        {
            for ( BaseY = StartY; BaseY <= EndY; ++BaseY )
            {
                Tile* Floor = GetTile ( BaseX, BaseY, Position.Z );

                if ( Floor && !Floor->Players.empty() )
                {
                    LPCreature = Floor->Players.begin();

                    do
                    {
                        List.push_back ( (*LPCreature) );

                        ++LPCreature;
                    }
                    while ( LPCreature != Floor->Players.end() );
                }
            }
        }

    return List;
}
Player* Game::GetCreatureByID ( UInt32& Identifier )
{
    if ( !Players.empty() )
    {
        PlayerList::iterator LPCreature = Players.begin();

        do
        {
            if ( (*LPCreature)->playerid == Identifier )
            {
                return (*LPCreature);
            }

            ++LPCreature;
        }
        while ( LPCreature != Players.end() );
    }

    return NULL;
}


game.h
Code:
#ifndef _GAME_H_
#define _GAME_H_

#include <string>
#include <list>
#include <vector>
#include <map>
#include "NetworkMessage.h"
#include "Definitions.h"
#include "Position.h"
#include "Player.h"
#include "Tile.h"
#include "Task.h"
#include <queue>

using std::priority_queue;
using std::map;
using std::list;
using std::vector;
using std::string;

typedef std::vector<Player*> PlayerList;
typedef PlayerList SpectatorList;
class Tile;
class Game
{
public:
    ~Game ( void );

    void Create ( void );
    /*Temprarly map loading*/
    bool LoadMapXml(std::string filename);
    /*Temprarly map loading*/

    SpectatorList GetSpectatorList ( Position_t& );

    Player* GetCreatureByID ( UInt32& Identifier );

    Tile* GetTile ( UInt16, UInt16, Byte );
    Tile* GetTile ( Position_t& );
    PlayerList Players;    
};

#endif

Reply With Quote
  #4  
Old October 1st, 2006, 04:18 PM
Java Robin XTF Java Robin XTF is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: New York City
Posts: 25 Java Robin XTF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 18 sec
Reputation Power: 0
Items.cpp:
Code:
#include "Items.h"

Item::Item ( void )
{
    _Identifier = 0;

    Count = 1;

    _Name = "";
    _Description = "";
}

Item::Item ( UInt32 Identifier )
{
    _Identifier = Identifier;

    Count = 1;

    _Name = "";
    _Description = "";
}

Item::Item ( UInt32 Identifier, Byte Stack )
{
    _Identifier = Identifier;

    Count = Stack;

    _Name = "";
    _Description = "";
}

Item::~Item ( void )
{
}

UInt16 Item::GetID ( void ) const
{
    return _Identifier;
}

void Item::SetID ( UInt16 Identifier )
{
    _Identifier = Identifier;
}

String Item::GetName ( void ) const
{
    return _Name;
}

void Item::SetName ( String Name )
{
    _Name = Name;
}

String Item::GetDescription ( void ) const
{
    return _Description;
}

void Item::SetDescription ( String Description )
{
    _Description = Description;
}

UInt16 Item::GetWeight ( void )
{
    return _Weight;
}

void Item::SetWeight ( UInt16 Weight )
{
    _Weight = Weight;
}

Byte Item::GetType ( void ) const
{
    return _Type;
}

void Item::SetType ( Byte Type )
{
    _Type = Type;
}

Item* Item::GetItem ( void )
{
    return this;
}

Reply With Quote
  #5  
Old October 1st, 2006, 04:49 PM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
Hey, Robin I can't download the files; I'm lost in the site the link points.

Reply With Quote
  #6  
Old October 1st, 2006, 05:35 PM
Java Robin XTF Java Robin XTF is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: New York City
Posts: 25 Java Robin XTF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 18 sec
Reputation Power: 0
It says "Please enter" and after that you are to enter the 3 letter code as shown. Once you enter it you click download and your download will commence accordingly.
Items.h
Code:
#ifndef _ITEMS_H_
#define _ITEMS_H_

#include <string>
#include "Definitions.h"
#include "Player.h"

class Item
{
public:

    Item ( void );
    Item ( UInt32 );
    Item ( UInt32, Byte );

    ~Item ( void );

    UInt16 GetID ( void ) const;
    void SetID ( UInt16 );

    String GetName ( void ) const;
    void SetName ( String );

    String GetDescription ( void ) const;
    void SetDescription ( String );

    UInt16 GetWeight ( void );
    void SetWeight ( UInt16 );

    Byte GetType ( void ) const;
    void SetType ( Byte );

    Item* GetItem ( void );

    Byte Count;

protected:

    UInt16 _Identifier;

    String _Name;
    String _Description;

    UInt16 _Weight;
    Byte   _Type;
};

#endif

Networkmessage.cpp
Code:
#include "NetworkMessage.h"
#include <string>

NetworkMessage::NetworkMessage ( void )
{
    _next = _buffer;

    _next = 0;
}

NetworkMessage::~NetworkMessage ( void )
{
}

bool NetworkMessage::WriteToSocket ( const SOCKET& socket )
{
    unsigned long mode;
    int result;

    mode = 1; /* Nonblocking */

    result = ioctlsocket ( socket, FIONBIO, &mode );

    if ( result == SOCKET_ERROR )
    {
        return false;
    }

    _buffer[0] = (unsigned char)_size;
    _buffer[1] = (unsigned char)(_size >> 8);

    int left = (_size + 2);
    char* buffer = _buffer;

    do
    {
        result = send ( socket, buffer, left, 0 );

        if ( result == SOCKET_ERROR )
        {
            return false;
        }

        if ( result == 0 ) /* Connection closed */
        {
            return false;
        }

        buffer += result;
        left -= result;
    }
    while ( left > 0 );

    mode = 0; /* Blocking */

    result = ioctlsocket ( socket, FIONBIO, &mode );

    return true;
}

bool NetworkMessage::ReadFromSocket ( const SOCKET& socket )
{
    _size = recv ( socket, _buffer, 2, 0 );

    if ( _size == SOCKET_ERROR )
    {
        return false;
    }

    if ( _size < 2 )
    {
        return false;
    }

    int result;

    _size = _buffer[0];
    _size += (_buffer[1] << 8);

    int left = _size;
    char* buffer = (_buffer + 2);

    do
    {
        result = recv ( socket, buffer, left, 0 );

        if ( result == SOCKET_ERROR )
        {
            return false;
        }

        if ( result == 0 ) /* Connection closed */
        {
            return false;
        }

        buffer += result;
        left -= result;
    }
    while ( left > 0 );

    _next = (_buffer + 2);

	return true;
}

void NetworkMessage::AddPosition ( Position_t Position )
{
    AddU16 ( Position.X );
    AddU16 ( Position.Y );

    AddByte ( Position.Z );
}

Position_t NetworkMessage::GetPosition ( )
{
    Position_t Position;

    Position.X = GetU16();
    Position.Y = GetU16();

    Position.Z = GetByte();

    return Position;
}

std::string NetworkMessage::GetString()
{
	int stringlen = GetU16();
	std::string lal = _next;
	int newnumber = atoi(lal.c_str());       
	if (stringlen >= (16384 - newnumber))
		return std::string();

	char* v = (char*)(_size+_next);
	_next += stringlen;
	return std::string(v, stringlen);
}

unsigned char NetworkMessage::GetByte ( void )
{
    unsigned char result = (*_next);

    _next++;

    return result;
}

unsigned short NetworkMessage::GetU16 ( void )
{
    unsigned short result = *(unsigned short*)_next;

    _next += 2;

    return result;
}

unsigned int NetworkMessage::GetU32 ( void )
{
    unsigned int result = *(unsigned int*)_next;

    _next += 4;

    return result;
}

void NetworkMessage::GetString ( char* string )
{
    unsigned short length = GetU16();

    memcpy ( string, _next, length );

    string[length] = '\0';

    _next += length;

	return;
}

void NetworkMessage::AddByte ( unsigned char number )
{
    *_next = number;

    _size++;
    _next++;

	return;
}

void NetworkMessage::AddU16 ( unsigned short number )
{
    unsigned short* buffer = (unsigned short*)_next;

    *buffer = number;

    _size += 2;
    _next += 2;

	return;
}

void NetworkMessage::AddU32 ( unsigned int number )
{
    unsigned int* buffer = (unsigned int*)_next;

    *buffer = number;

    _size += 4;
    _next += 4;

	return;
}

void NetworkMessage::AddString ( char* string )
{
    if ( string == NULL )
	{
		return;
	}

    unsigned short length = (unsigned short)strlen ( string );

    AddU16 ( length );
    memcpy ( _next, string, length );

    _size += length;
    _next += length;

	return;
}

void NetworkMessage::Move ( int from, int to )
{
	if ( to <= from )
	{
		return;
	}

	char* from_buffer = &_buffer[from];
	char* to_buffer = &_buffer[to];

    size_t length = (size_t)(to_buffer - from_buffer);

    memmove ( to_buffer, from_buffer, length );
    memset ( from_buffer, 0, length );

	return;
}

void NetworkMessage::Reset ( void )
{
    _size = 0;
    _next = (_buffer + 2);

	return;
}


void NetworkMessage::Skip ( void )
{
    _size++;
    _next++;

	return;
}

void NetworkMessage::Skip ( unsigned int count )
{
    _size += count;
    _next += count;

	return;
}

char& NetworkMessage::operator [] ( unsigned int index )
{
	return _buffer[index];
}

Networkmessage.h
Code:
#ifndef _NETWORK_MESSAGE_H_
#define _NETWORK_MESSAGE_H_

#pragma once

#include <winsock2.h>
#include "Position.h"
#include <cstring>
#include <string>
#include "Definitions.h"
#define NM_MAX_SIZE 16768

class NetworkMessage
{
public:

    NetworkMessage ( void );

    ~NetworkMessage ( void );

    /*
    @WriteToSocket: Sends the current buffer to the specified connection.

    Parameters:
                1. const SOCKET& -> The socket that is to receive the buffer.
    */
    bool WriteToSocket ( const SOCKET& socket );
    /*
    @ReadFromSocket: Receives the buffer from the specified connection.

    Parameters:
                1. const SOCKET& -> The socket which the message is to be
                                    read from.
    */
    bool ReadFromSocket ( const SOCKET& socket );

void AddPosition ( Position_t Position );
Position_t GetPosition ( );

unsigned getLength() { return _size; }

    void Pop ( void )
    {
        _next++;
    }

std::string    GetString();


    /*
    @GetByte: Returns a byte from current message's buffer.

    Parameters: This function requires no parameters.
    */
    unsigned char GetByte ( void );
    /*
    @GetU16: Returns a 2-byte unsigned integer from the current message's
             buffer.

    Parameters: This function requires no parameters.
    */
    unsigned short GetU16 ( void );
    /*
    @GetU32: Returns a 4-byte unsigned integer from the current message's
             buffer.

    Parameters: This function requires no parameters.
    */
    unsigned int GetU32 ( void );
    /*
    @GetString: Returns a string from current message's buffer.

    Parameters:
                1. string -> A pointer to a character buffer that is
                             to receive the string.
    */
    void GetString ( char* string );

    /*
    @AddByte: Inserts a byte into the message buffer.

    Parameters:
                1. number -> The byte that is to be insert.
    */
    void AddByte ( unsigned char number );
    /*
    @AddU32: Inserts a 2-byte unsigned integer into message's buffer.

    Parameters:
                1. number -> The 2-byte unsigned integer that is
                             to be insert.
    */
    void AddU16 ( unsigned short number );
    /*
    @AddU32: Inserts a 4-byte unsigned integer into message's buffer.

    Parameters:
                1. number -> The 4-byte unsigned integer that is
                             to be insert.
    */
    void AddU32 ( unsigned int number );
    /*
    @AddString: Inserts a string into message's buffer.

    Parameters:
                1. string -> A pointer to the null-terminated string that
                             is to be insert.

    Remarks: AddString does not add the null-terminator in message's
             buffer.
    */
    void AddString ( char* string );

    /*
	@Move: Moves message's buffer and sets all moved bytes to 0.

	Parameters:
	            1. from -> The position where the buffer is to be moved from.
				2. to -> The position where the buffer is to be moved to.
	*/
	void Move ( int from, int to );

    /*
    @Reset: Sets the reading/writting positions to, respectivelly, 2 and 0.

    Parameters: This function requires no parameters.
    */
    void Reset ( void );

    /*
    @Skip: Skips the next byte to be read from message's buffer.

    Parameters: This function requires no parameters.
    */
    void Skip ( void );
    /*
    @Skip (Overload): Skips the specified number of bytes to be read from
                      message's buffer.

    Parameters:
                1. unsigned -> The number of bytes that are to be skipped.
    */
    void Skip ( unsigned int count );

	/*
	@operator []: Returns a reference to a certain location at message's
	              buffer.

    Parameters:
	            1. index -> The position where the character is to be
				            retrieved.
    */
	char& operator [] ( unsigned int index );

protected:

    char _buffer[NM_MAX_SIZE];
    char* _next;

    unsigned _size;
};

#endif

Reply With Quote
  #7  
Old October 1st, 2006, 09:21 PM
Java Robin XTF Java Robin XTF is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: New York City
Posts: 25 Java Robin XTF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 18 sec
Reputation Power: 0
OTserv.cpp
Code:
     #include <iostream>
     #include <process.h>
     #include <windows.h>
     #include <string>


#include "Otserv.h"
/*Otserv Header*/

#include "Definitions.h"
/*Definition Header*/

#include "Protocol.h"
/*Protocol Recieving*/

#include "Account.h"
/*Account file Header*/

#include "Player.h"
/*Player file Header*/

#include "Game.h"
/*Public Game Header*/
Game game;

/*
Vitor you are best ;) :P
*/
void onPlayerConnect ( void* data )
{
    SOCKET socket = *(SOCKET*)data;
  //  Protocol* protocol;
    NetworkMessage read;
//puts ( (const char*) protocol->GetSocket() );

    if ( read.ReadFromSocket ( socket ) )
    {
    //protocol->SetSocket ( socket );
    
   unsigned short protocol_id = read.GetU16(); 
      if ( protocol_id == 0x0201 )
        {
            read.Skip();

            unsigned short client_version = read.GetU16();

            if ( client_version != 760 )
            {
                read.AddByte ( 0x0A );
                read.AddString ( "You must login with Tibia client version 7.6." );
                read.WriteToSocket ( socket );
                closesocket ( socket );
                _endthread(); /* Return */
            }

            read.Skip ( 12 );
  // login server connection
    unsigned int accnumber = read.GetU32();
    char password[30];
    read.GetString ( password );

    read.Reset();

    Account account;
    char accstring[16];
    itoa(accnumber, accstring, 10);

    if (account.openAccount(accstring, password))
    {
      read.AddByte(0x14);
      read.AddString("1\nWelcome to Drakaro new Source.");

      read.AddByte(0x64);
      read.AddByte(account.charList.size());

      list<string>::iterator it;
      for (it = account.charList.begin(); it != account.charList.end(); it++)
      {
        read.AddString((char*)(*it).c_str());
        read.AddString("Drakaro");
        read.AddU32(inet_addr("127.0.0.1"));
        read.AddU16(7171);
      }

      read.AddU16(account.premDays);
    }
    else
    {
      read.AddByte(0x0A);
      read.AddString("Please enter a valid account number and password.");
    }

    read.WriteToSocket(socket);

    closesocket(socket);
  }
  // gameworld connection to my server :D
  else if (protocol_id == 0x020A)
  {			
unsigned char  unknown = read.GetByte();
unsigned long accnumber = read.GetU32();							
std::string name;
read.GetString( (char*) name.c_str() );
std::string password = read.GetString();
read.Reset(); 
//reset it :D
Protocol protocol(socket);
Player player ( "Hurzel"/*, &protocol*/ );
//we needed these ;) use this protocol declare else it'l crash.
Account account;
if (player.LoadPlayer(player._name, "lol"))
{
protocol.SendLogin(read);
protocol.ReceiveLoop();
}
//end of sending player ****
read.WriteToSocket(socket);
//write to socket :)
  }
}

    _endthread(); /* Return */
}

int main ( int argc, char* argv[] )
{
	int result;
    WORD version;
    WSADATA wsa_data;

    version = MAKEWORD ( 2, 2 );

    result = WSAStartup ( version, &wsa_data );

    if ( result != NO_ERROR )
    {
        puts ( "Fatal Error: There is no usable WinSock DLL!" );

        return -1;
    }

    if ( LOBYTE ( wsa_data.wVersion ) != 2 || HIBYTE ( wsa_data.wVersion ) != 2 )
    {
        puts ( "Fatal Error: There is no usable WinSock DLL with the requested version (2.2)." );

        WSACleanup();

        return - 1;
    }

    SOCKET listener;

    listener = socket ( AF_INET, SOCK_STREAM, IPPROTO_IP );

    if ( listener == INVALID_SOCKET )
    {
        puts ( "Fatal Error: It was not possible to create the main socket." );

        WSACleanup();

        return -1;
    }

    sockaddr_in service;

    service.sin_family = AF_INET;
    service.sin_addr.s_addr = inet_addr("127.0.0.1");
    service.sin_port = htons ( 7171 );

    result = bind ( listener, (sockaddr*)&service, sizeof(sockaddr_in) );

    if ( result != NO_ERROR )
    {
        puts ( "Fatal Error: It was not possible to bind the main socket." );

        closesocket ( listener );

        WSACleanup();

        return -1;
    }

    result = listen ( listener, SOMAXCONN );

    if ( result == SOCKET_ERROR )
    {
        puts ( "Fatal Error: It was not possible to set the main socket on listening mode." );

        closesocket ( listener );

        WSACleanup();

        return -1;
    }

	printf ( ":: Creating Map...\t" );
	//loading unit
    //const char* filename;
    game.LoadMapXml("data/map.xml");
    //game.Create();
    //cout << game.GetTile((46),(54),(7))<< "\t\n";
    
	puts ( "[Done]\n::" );

    puts ( ":: OTServ is running..." );
//std::cout << "\n:: socket is:\t" << socket << std::endl;
//std::cout << "\n:: port is:\t" << service.sin_port << std::endl;
    SOCKET accepted = INVALID_SOCKET;

	uintptr_t thread_handle;
    fd_set reads;
    /* timeval tv = { 2, 0 }; */

    while ( true )
    {
        FD_ZERO ( &reads );
        FD_SET ( listener, &reads );

        result = select ( 1, &reads, NULL, NULL, NULL );

        if ( result == SOCKET_ERROR )
        {
            break;
        }

        do
        {
            accepted = accept ( listener, NULL, NULL );
        }
        while ( accepted == INVALID_SOCKET );

        thread_handle = _beginthread ( onPlayerConnect, 0, (void*)&accepted );

        if ( thread_handle == -1L )
        {
            printf ( "Error creating thread: %d", errno );
        }
    }

	puts ( "Fatal: Program terminated due to a connection error." );

    return 0;
}

OTserv.h
Code:
/* Not added */

Reply With Quote
  #8  
Old October 1st, 2006, 09:22 PM
Java Robin XTF Java Robin XTF is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: New York City
Posts: 25 Java Robin XTF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 18 sec
Reputation Power: 0
Player.cpp
Code:
/////////////////////////////////////////////////////////////////////////////
// The New OTServ - an opensource server for the MMORPG Tibia              //
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or           //
// modify it under the terms of the GNU General Public License             //
// as published by the Free Software Foundation; either version 2          //
// of the License, or (at your option) any later version.                  //
//                                                                         //
// This program is distributed in the hope that it will be useful,         //
// but WITHOUT ANY WARRANTY; without even the implied warranty of          //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
// GNU General Public License for more details.                            //
//                                                                         //
// You should have received a copy of the GNU General Public License       //
// along with this program; if not, write to the Free Software Foundation, //
// Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.         //
/////////////////////////////////////////////////////////////////////////////

#include "Player.h"
#include "Tools.h"
#include "Account.h"

Game Map;
Tile til;

Player::Player (const char *name/*, Protocol *p*/)
{
/*player ****t*/
uid = (10 | PLAYER_ID_RANGE);
_name = "Hurzel";
Sex = 0;
Direction = 0;
Voc = 0;
Health = 100;
MaxHealth = 100;
Food = 0;
Mana = 100;
MaxMana = 100;
ManaSpent = 0;
Access = 1;
Speed = 200;
Soul = 100;
Experience = 0;
Level = 1;
LevelProcent = 0;
MagLevel = 0;
MagProcent = 0;
Capicity = 100;
LookType = 0;
LookHead = 0;  
LookBody = 0;
LookLegs = 0;
LookFeet = 0; 
SkillId  = 0; 
SkillLevel = 0;
SkillTries = 0;
PosX = 30;
PosY = 30;
PosZ = 7;  

playerid = 1;
//Position = Position_t ( 50, 50, 7 );
Position = Position_t ( PosX, PosY, PosZ );
}

Player::~Player()
{
                 
}


bool Player::LoadPlayer(const string &name, const string &givenpassword)
{
	std::string filename="data/players/"+name+".xml";
	std::transform(filename.begin(), filename.end(), filename.begin(), (int(*)(int))tolower);

	xmlDocPtr doc;
	doc = xmlParseFile(filename.c_str());

  Player* thiss = new Player( (char*)name.c_str()/*, this*/ );

  if (doc)
  {
    xmlNodePtr root, tmp, p, slot;
	  root=xmlDocGetRootElement(doc);

	  if (xmlStrcmp(root->name,(const xmlChar*) "player"))
    {
		  std::cout << "Strange. Player-Savefile was no savefile for " << name << std::endl;
	  }

	  p = root->children;
	  
	  const char *account = (const char*)xmlGetProp(root, (const xmlChar *) "account");
      Account iaccount;
      if (!iaccount.openAccount(account, givenpassword))
      return false;

	  this->Sex=atoi((const char*)xmlGetProp(root, (const xmlChar *) "sex"));
	  this->Direction=atoi((const char*)xmlGetProp(root, (const xmlChar *) "lookdir"));
	  this->Experience=atoi((const char*)xmlGetProp(root, (const xmlChar *) "exp"));
      thiss->Level=atoi((const char*)xmlGetProp(root, (const xmlChar *) "level"));
      this->MagLevel=atoi((const char*)xmlGetProp(root, (const xmlChar *) "maglevel"));
      thiss->Capicity=atoi((const char*)xmlGetProp(root, (const xmlChar *) "cap"));
	  this->Voc=atoi((const char*)xmlGetProp(root, (const xmlChar *) "voc"));
	  this->Access=atoi((const char*)xmlGetProp(root, (const xmlChar *) "access"));

	  while (p)
    {
		  std::string str=(char*)p->name;
		  if(str=="mana")
      {
			  this->Mana=atoi((const char*)xmlGetProp(p, (const xmlChar *) "now"));
			  this->MaxMana=atoi((const char*)xmlGetProp(p, (const xmlChar *) "max"));
			  this->ManaSpent=atoi((const char*)xmlGetProp(p, (const xmlChar *) "spent"));
		  }
		  else if(str=="position")
      {
			  this->PosX=atoi((const char*)xmlGetProp(p, (const xmlChar *) "x"));
			  this->PosY=atoi((const char*)xmlGetProp(p, (const xmlChar *) "y"));
			  this->PosZ=atoi((const char*)xmlGetProp(p, (const xmlChar *) "z"));
		  }
		  else if(str=="health")
      {
			  this->Health=atoi((const char*)xmlGetProp(p, (const xmlChar *) "now"));
			  this->MaxHealth=atoi((const char*)xmlGetProp(p, (const xmlChar *) "max"));
			  this->Food=atoi((const char*)xmlGetProp(p, (const xmlChar *) "food"));
		  }
		  else if(str=="look")
      {
			  this->LookType=atoi((const char*)xmlGetProp(p, (const xmlChar *) "type"));
			  this->LookHead=atoi((const char*)xmlGetProp(p, (const xmlChar *) "head"));
			  this->LookBody=atoi((const char*)xmlGetProp(p, (const xmlChar *) "body"));
			  this->LookLegs=atoi((const char*)xmlGetProp(p, (const xmlChar *) "legs"));
			  this->LookFeet=atoi((const char*)xmlGetProp(p, (const xmlChar *) "feet"));
		  }
		  else if(str=="skills")
      {
			  tmp=p->children;
			  while(tmp)
        {
				  int s_id, s_lvl, s_tries;
          if (strcmp((const char*)tmp->name, "skill") == 0)
          {
				    this->SkillId=atoi((const char*)xmlGetProp(tmp, (const xmlChar *) "skillid"));
				    this->SkillLevel=atoi((const char*)xmlGetProp(tmp, (const xmlChar *) "level"));
				    this->SkillTries=atoi((const char*)xmlGetProp(tmp, (const xmlChar *) "tries"));
          }
          tmp=tmp->next;
			  }
		  }
		  p=p->next;
	  }
	  std::cout << "loaded " << filename << std::endl;
	  xmlFreeDoc(doc);
	  
  	return true;
  }

  return false;
}

/*NEW REPAIRED PARTS*/
void Player::SendLogin ( Player* player, NetworkMessage& Message, int times )
{ 
/* start adding the players to all lists! */
/* add the player to the games onlinelist */  
for(int i = 0; i < times; ++i){
        

PlayerList Players;
Players.push_back ( player );
if ( !Players.empty() )
{
    PlayerList::iterator LPCreature = Players.begin();
    if((*LPCreature) == player){
    cout << "\nplayer on onlinelist added id = " << (*LPCreature);
    }
}
/* add the player to the games onlinelist */  
/* add the player to the map and retrieve it */
SpectatorList List = Map.GetSpectatorList( player->Position ); 
List.push_back ( player );
if(!List.empty())
{
   SpectatorList::iterator LPCreature = List.begin();
   if((*LPCreature) == player){
   cout << "\nplayer on map added id = " <<(*List.begin());   
   }
}
/* add the player to the map and retrieve it */
/* add the player to the tile */
TilePlayerList List1;
List1.push_back ( player );
if(!List1.empty())
{
   TilePlayerList::iterator LPCreature = List1.begin();
   if((*LPCreature) == player){
   cout << "\nplayer on tile added id = " <<(*List1.begin());   
   }
}
/* add the player to the tile */
Map.Players.push_back ( player );

/* end adding the players to all lists! */

    Players.push_back ( player );
    PlayerList::iterator LPCreature = Players.begin();

  if ( (*LPCreature) == player )
  {
     SendCreatureLogin ( player, Message );
  }
  til.PlaceCreature ( player );
}

//gosh this was work :O :) 
}

void Player::SendCreatureLogin ( Player* player, NetworkMessage& Message )
{
    Tile* CTile = Map.GetTile ( player->Position );
                                
    if ( !CTile )
    {
        player->Position = Position_t ( player->PosX, player->PosY, player->PosZ );

        CTile = Map.GetTile ( player->PosX, player->PosY, player->PosZ );
    }     
     
    Message.AddU16(0x61);
    Message.AddU32(0 );
    Message.AddU32(player->playerid );
    Message.AddString((char*)player->_name);
    
    Message.AddByte ( ((player->Health * 100) / player->MaxHealth) ); // Life Percentage
    Message.AddByte ( 2 );
    Message.AddByte ( 134 );
    Message.AddByte ( 0 );
    Message.AddByte ( 30 );
    Message.AddByte ( 40 );
    Message.AddByte ( 50 );
    Message.AddByte ( 0x00 ); // Light Level
    Message.AddByte ( 0xD7 ); // Light Color
    Message.AddU16 ( 999 );
    Message.AddByte ( 0 );
    Message.AddByte ( 0 );


}

bool Player::CanSee ( UInt16& X, UInt16& Y, Byte& Z) const
{
    if ( Position.Z >= 7 && Z < 7 || Z >= 7 && Position.Z < 7)
    {
        return false;
    }

    int Offset = (Position.Z - Z); /* Floor Variation */

    if ( X >= (Position.X - 8 + Offset) && X <= (Position.X + 9 + Offset) &&
         Y >= (Position.Y - 6 + Offset) && Y <= (Position.Y + 7 + Offset) )
    {
        return true;
    }

    return false;
}

bool Player::CanSee ( Position_t& LookPosition ) const
{
    if ( Position.Z > 7 && LookPosition.Z <= 7 || Position.Z <= 7 && LookPosition.Z > 7 )
    {
        return false;
    }

    int Offset = (Position.Z - LookPosition.Z); /* Floor Variation */

    if ( LookPosition.X >= (Position.X - 8 + Offset) && LookPosition.X <= (Position.X + 9 + Offset) &&
         LookPosition.Y >= (Position.Y - 6 + Offset) && LookPosition.Y <= (Position.Y + 7 + Offset) )
    {
        return true;
    }

    return false;
}

player.h in next post..

Reply With Quote
  #9  
Old October 1st, 2006, 09:23 PM
Java Robin XTF Java Robin XTF is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: New York City
Posts: 25 Java Robin XTF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 18 sec
Reputation Power: 0
player.h
Code:
/////////////////////////////////////////////////////////////////////////////
// The New OTServ - an opensource server for the MMORPG Tibia              //
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or           //
// modify it under the terms of the GNU General Public License             //
// as published by the Free Software Foundation; either version 2          //
// of the License, or (at your option) any later version.                  //
//                                                                         //
// This program is distributed in the hope that it will be useful,         //
// but WITHOUT ANY WARRANTY; without even the implied warranty of          //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
// GNU General Public License for more details.                            //
//                                                                         //
// You should have received a copy of the GNU General Public License       //
// along with this program; if not, write to the Free Software Foundation, //
// Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.         //
/////////////////////////////////////////////////////////////////////////////

#ifndef _PLAYER_H_
#define _PLAYER_H_

#include "NetworkMessage.h"
#include "Protocol.h"
#include "Definitions.h"
#include "Position.h"
#include "Items.h"
#include "Game.h"
#include "Enums.h"
#include <string>
#include <set>
using namespace std;

#define PLAYER_ID_RANGE 0x10000000

#include <list>
#include <vector>
#include <map>
using std::list;
using std::vector;
using std::map;

class Player;

typedef map<unsigned long, Player*> PlayersIDList;

//currentTest
typedef std::vector<Player*> TestList;


typedef PlayersIDList chatlist;
typedef vector<Player*> SpectatorVector;

class Item;
class Protocol;

class Player
{
public:
Player(const char *name/*, Protocol *p*/);
virtual ~Player();

Item* Inventory[11]; 

Position_t Position;

bool LoadPlayer(const string &name, const string &givenpassword);

int playerid;

int Sex;
int Direction;
int Voc;
int Health;
int MaxHealth;
int Food;
int Mana;
int MaxMana;
int ManaSpent;
int Access;
int Speed;
int Soul;
int Experience;
int Level;
int LevelProcent;
int MagLevel;
int MagProcent;
int Capicity;
int LookType;
int LookHead;  
int LookBody;
int LookLegs;
int LookFeet; 
int SkillId; 
int SkillLevel;
int SkillTries;
int PosX;
int PosY;
int PosZ;
const char* _name;

SOCKET s;

Player* GetPlayer ( void )
{
return this;
}

/*NEW REPAIRED PARTS*/
unsigned long uid;

bool CanSee ( UInt16&, UInt16&, Byte& ) const;
bool CanSee ( Position_t& ) const;
void SendCreatureLogin ( Player* player, NetworkMessage& Message );
void SendLogin ( Player* player, NetworkMessage& Message, int times );
          
};



#endif

Position.h
Code:
/////////////////////////////////////////////////////////////////////////////
// The New OTServ - an opensource server for the MMORPG Tibia              //
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or           //
// modify it under the terms of the GNU General Public License             //
// as published by the Free Software Foundation; either version 2          //
// of the License, or (at your option) any later version.                  //
//                                                                         //
// This program is distributed in the hope that it will be useful,         //
// but WITHOUT ANY WARRANTY; without even the implied warranty of          //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
// GNU General Public License for more details.                            //
//                                                                         //
// You should have received a copy of the GNU General Public License       //
// along with this program; if not, write to the Free Software Foundation, //
// Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.         //
/////////////////////////////////////////////////////////////////////////////

#ifndef _POSITION_H_
#define _POSITION_H_

#include "Definitions.h"

struct Position_t
{
    Position_t ( void )
    : X(0), Y(0), Z(0)
    {
    }

    Position_t ( UInt16 _X, UInt16 _Y, Byte _Z )
    : X(_X), Y(_Y), Z(_Z)
    {
    }

    Boolean operator == ( Position_t& Position )
    {
        return (X == Position.X && Y == Position.Y && Z == Position.Z);
    }

    UInt16 X;
    UInt16 Y;

    Byte Z;
};

#endif

Reply With Quote
  #10  
Old October 1st, 2006, 09:25 PM
Java Robin XTF Java Robin XTF is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: New York City
Posts: 25 Java Robin XTF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 18 sec
Reputation Power: 0
Protocol.cpp
Code:
#include "Protocol.h"
#include "Definitions.h"
#include "Player.h"

extern Game game;
Tile tile;

using namespace std;

Protocol::Protocol(SOCKET s)
{
	OTSYS_THREAD_LOCKVARINIT(bufferLock);
	this->s = s;
	placed = false;
}


Protocol::~Protocol()
{

	OTSYS_THREAD_LOCKVARRELEASE(bufferLock);
	
	if(s != 0) {	
	   closesocket(s);
	   s = 0;
	}
}



void Protocol::ReceiveLoop()
{
NetworkMessage msg;

    while(msg.ReadFromSocket(s)){
			parsePacket(msg);
      }
	if(s != 0) {	
	   closesocket(s);
	   s = 0;
	}
}




void Protocol::parsePacket(NetworkMessage &msg)
{
     /*
	if(msg.getLength() <= 0)
		return;
		*/
	Player* player = new Player( player->_name/*, this */);	
	unsigned char recievedbyte = msg.GetByte();
    std::cout << "\nGOT BYTE:" << (int)recievedbyte << std::endl;
    	
          
    	
    switch ( recievedbyte )
    {
        case 0x14:
        SendLogout( player );
        break;

        case 0x1E:
        cout << "check";
        break;

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

        default:
        {
        puts ("fer****ed im missing a byte..");    
        }
        break;
    }
}

void Protocol::SendLogin ( NetworkMessage &msg )
{
     Player* player = new Player( player->_name/*, this*/ );

     msg.AddByte(0x0A);
     msg.AddU32( player->playerid/*player ID*/ );
	 msg.AddByte(0x32);
	 msg.AddByte(0x00);
            
     msg.AddByte(0x00); //can report bugs 0,1
     //TODO: GM ACTIONS
	 //map description
	 msg.AddByte(100);   
	 msg.AddPosition(player->Position);
     
	 //start container part    
     SendMapDescription ( player, msg, (player->PosX - 8), (player->PosY - 6), player->PosZ, 18, 14 );
     //magic effect NM_ME_ENERGY_AREA
     msg.AddByte(0x83);
	 msg.AddPosition(player->Position);
     
	 msg.AddByte(ME_BLUE_BUBBLE); //login buble

     msg.AddByte(0xA0);             //stats header
	 msg.AddU16(player->Health /*player health*/);
	 msg.AddU16(player->MaxHealth/*player->getPlayerInfo*//*player max health*/);
	 msg.AddU16(player->Capicity/*(unsigned short)std::floor*//*free cap*/);
	 msg.AddU32(player->Experience /*exp*/);
	 msg.AddU16(player->Level /*level*/);
	 msg.AddByte(player->LevelProcent /*% to lvl*/);
	 msg.AddU16(player->Mana /*mana*/);
	 msg.AddU16(player->MaxMana /*max mana*/);
	 msg.AddByte(player->MagLevel /*magic lvl*/);
	 msg.AddByte(player->MagProcent /*magic lvl %*/);
	 msg.AddByte(player->Soul /*soul*/);

     msg.AddByte(0x82);    //world light header
     msg.AddByte (0x6F /*light level*/);
     msg.AddByte (0xD7 /*light color*/);
     
     msg.AddByte(0x8D);    //creature light header
     msg.AddU32(1 /*player id*/);
     msg.AddByte(0 /*light level*/);
     msg.AddByte(0xD7 /*light color*/);

     //inventory      
     msg.AddByte (0x79);  //slot header
     msg.AddByte (1);  //slot id
     msg.AddByte (0x79);  //slot header
     msg.AddByte (2);  //slot id
     msg.AddByte (0x79);  //slot header
     msg.AddByte (3);  //slot id
     msg.AddByte (0x79);  //slot header
     msg.AddByte (4);  //slot id
     msg.AddByte (0x79);  //slot header
     msg.AddByte (5);  //slot id
     msg.AddByte (0x79);  //slot header
     msg.AddByte (6);  //slot id
     msg.AddByte (0x79);  //slot header
     msg.AddByte (7);  //slot id
     msg.AddByte (0x79);  //slot header
     msg.AddByte (8);  //slot id
     msg.AddByte (0x79);  //slot header
     msg.AddByte (9);  //slot id
     msg.AddByte (0x79);  //slot header
     msg.AddByte (10);  //slot id
	 
	 msg.AddByte(0xA1);        //skills header
	 

    msg.AddByte(10 /*skill lvl*/);
    msg.AddByte(0 /*skill %*/);
    msg.AddByte(10 /*skill lvl*/);
    msg.AddByte(0 /*skill %*/);
    msg.AddByte(10 /*skill lvl*/);
    msg.AddByte(0 /*skill %*/);
    msg.AddByte(10 /*skill lvl*/);
    msg.AddByte(0 /*skill %*/);
    msg.AddByte(10 /*skill lvl*/);
    msg.AddByte(0 /*skill %*/);
    msg.AddByte(10 /*skill lvl*/);
    msg.AddByte(0 /*skill %*/);
    msg.AddByte(10 /*skill lvl*/);
    msg.AddByte(0 /*skill %*/);
       
     msg.WriteToSocket(s);
}

void Protocol::SendLogout ( Player* player )
{
     tile.RemoveCreature( player );
     delete player;
     closesocket ( GetSocket() );
}

void Protocol::SendMapDescription ( Player* player, NetworkMessage& Message, UInt16 X, UInt16 Y, Byte Z, UInt16 Width, UInt16 Height )
{
    int TileSkip = -1; /* Blank Tiles */

    int BaseZ, EndZ, LayerStep;

    if ( Z > 7 ) /* Underground */
    {
        BaseZ = (Z - 2);
        EndZ = Min ( 15, (Z + 2) );

        LayerStep = 1;
    }
    else
    {
        BaseZ = 7;
        EndZ = 0;

        LayerStep = -1;
    }
    
  for ( /* Nothing */; BaseZ != (EndZ + LayerStep); BaseZ += LayerStep )
    {
        int Offset = (Z - BaseZ);

        for ( int BaseX = 0; BaseX < Width; ++BaseX )
        {
        
            for ( int BaseY = 0; BaseY < Height; ++BaseY )
            {
            
            Tile* Floor = game.GetTile ( (X + BaseX + Offset), (Y + BaseY + Offset), BaseZ );
            
              if ( Floor != NULL )
                {
                    if ( TileSkip >= 0 )
                    {
                        Message.AddByte ( TileSkip );
                        Message.AddByte ( 0xFF );
                    }
                    
                    SendTile ( Message, Floor );
                    
                    
                    TileSkip = 0;
                }
                else
                {
                    TileSkip++;

                    if ( TileSkip == 0xFF ) 
                    {
                        Message.AddU16 ( 0xFFFF );

                        TileSkip = -1;
                    }
                }
              //nw  
            }
            //nw
        }
        //nw
    }
    //w 90%
            
        
    if ( TileSkip >= 0 )
    {
        Message.AddByte ( TileSkip );
        Message.AddByte ( 0xFF );
    }
}



void Protocol::parseSay(NetworkMessage &msg)
{
  Player* player = new Player( "Hurzel"/*, this*/ );
  unsigned char type = msg.GetByte();
	std::string text;
    msg.GetString( (char*)text.c_str() );


      switch(type)
      {
      case 0x01:
      creatureSay(msg, player, type, text); 
      break;
      }
}

void Protocol::creatureSay(NetworkMessage msg, Player *player, unsigned char type, const std::string &text)
{
	// First, check if this was a GM command
	if(text[0] == '/')
	{
		// Get the command
		switch(text[1])
		{
			default:break;
			// Summon?
			case 's':
			{
				puts ("cmd check");
				cout << player;
				Player* plays = new Player( "Player" );
				player->SendLogin( plays, msg, 1 );
			break; // case 's':
            } 
		}
	}
else{
        /*  msg.AddByte (0x78);  //slot header
     msg.AddByte (3);  //slot id
     msg.AddU16  (2869);*/
    //UpdateInventoryItem(msg, IS_BACKPACK, 2869);
     

NetworkMessage msg1;

    msg1.AddByte(0xAA);
	msg1.AddString("Hurzel");

	msg1.AddByte(0x01);
	msg1.AddPosition(player->Position);
	msg1.AddString( "oi" );
	
	msg1.WriteToSocket(s);



}

}

void Protocol::SendTile ( NetworkMessage& Message, Tile* Floor )
{
Player* player = new Player( player->_name );
Tile* Floor1 = game.GetTile ( player->Position.X, player->Position.Y, player->Position.Z );

   Message.AddU16 ( Floor->GetGroundID() );
   if( placed == false ){
   player->SendLogin( player, Message, 1 );
   placed = true;
   }
   
    if ( !Floor->DownItems.empty() )
    {
        ItemList::iterator LPItem = Floor->DownItems.begin();

        do
        {
        Message.AddU16 ( (*LPItem)->GetID() );       

            ++LPItem;
        }
        while ( LPItem != Floor->DownItems.end() );
    }

}

void Protocol::UpdateTile ( Tile* Floor )
{
Position_t Position;
Position = Position_t(Floor->X, Floor->Y, Floor->Z);
    SpectatorList List = game.GetSpectatorList ( Position );

    if ( !List.empty() )
    {
        SpectatorList::iterator LPCreature = List.begin();

        Player* Spectator;

        do
        {
            Spectator = (*LPCreature)->GetPlayer();

            if ( Spectator )
            {
                SendTileUpdate ( Floor );
            }

            ++LPCreature;
        }
        while ( LPCreature != List.end() );
    }
}

void Protocol::SendTileUpdate ( Tile* Floor )
{
    NetworkMessage Message;

    Message.AddByte ( 0x69 );

    Message.AddU16 ( Floor->X );
    Message.AddU16 ( Floor->Y );
    Message.AddByte ( Floor->Z );

    if ( Floor )
    {
        SendTile ( Message, Floor );

        Message.AddByte ( 0x00 );
        Message.AddByte ( 0xFF );
    }
    else /* Skip Tile */
    {
        Message.AddByte ( 0x01 );
        Message.AddByte ( 0xFF );
    }

    Message.WriteToSocket ( GetSocket() );
}

void Protocol::UpdateInventoryItem(NetworkMessage& msg, Slot_t slot, int Item)
{

		msg.AddU16(10);
		msg.AddU32(10);
		msg.AddByte(10);
		msg.GetString();
	
}

Reply With Quote
  #11  
Old October 1st, 2006, 09:25 PM
Java Robin XTF Java Robin XTF is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: New York City
Posts: 25 Java Robin XTF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 18 sec
Reputation Power: 0
Protocol.h
Code:
#ifndef __PROTOCOL_H__
#define __PROTOCOL_H__

#include <string>
#include <iostream>
#include <sstream>
#include <list>

#include "networkmessage.h"
#include "Definitions.h"
#include "Tile.h"
#include "Enums.h"

using namespace std;

class NetworkMessage;
class Protocol;

class Tile;
class Protocol
{
public:
Protocol(SOCKET s);
~Protocol();

    
    void ReceiveLoop ();

    void parsePacket ( NetworkMessage& msg);
    void SendLogin ( NetworkMessage &msg );
    void SendMapDescription ( Player* player, NetworkMessage& Message, UInt16 X, UInt16 Y, Byte Z, UInt16 Width, UInt16 Height );
    void SendTile ( NetworkMessage&, Tile* );
    //speak parts
    void parseSay(NetworkMessage &msg);
    void creatureSay(NetworkMessage msg, Player *player, unsigned char type, const std::string &text);
    //end speak parts
    //ParsePacket functions
    void SendLogout ( Player* );
    //ParsePacket functions

    SOCKET GetSocket ( void ) const
    {
        return s;
    }

    void SetSocket ( SOCKET NewSocket )
    {
        s = NewSocket;
    }
    
    void UpdateInventoryItem(NetworkMessage&, Slot_t slot, int Item);
    
    void UpdateTile ( Tile* );
    void SendTileUpdate ( Tile* );

private:
    bool placed;
    Player* play;    
    SOCKET s;
    OTSYS_THREAD_LOCKVAR bufferLock;
};

#endif

Thing.cpp
Code:
/////////////////////////////////////////////////////////////////////////////
// The New OTServ - an opensource server for the MMORPG Tibia              //
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or           //
// modify it under the terms of the GNU General Public License             //
// as published by the Free Software Foundation; either version 2          //
// of the License, or (at your option) any later version.                  //
//                                                                         //
// This program is distributed in the hope that it will be useful,         //
// but WITHOUT ANY WARRANTY; without even the implied warranty of          //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
// GNU General Public License for more details.                            //
//                                                                         //
// You should have received a copy of the GNU General Public License       //
// along with this program; if not, write to the Free Software Foundation, //
// Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.         //
/////////////////////////////////////////////////////////////////////////////

#include "Thing.h"

Thing::Thing ( void )
{
    Position = Position_t( 0, 0, 0 );
}

Player* Thing::GetPlayer ( void )
{
    return NULL;
}

Item* Thing::GetItem ( void )
{
    return NULL;
}

Thing.h
Code:
/////////////////////////////////////////////////////////////////////////////
// The New OTServ - an opensource server for the MMORPG Tibia              //
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or           //
// modify it under the terms of the GNU General Public License             //
// as published by the Free Software Foundation; either version 2          //
// of the License, or (at your option) any later version.                  //
//                                                                         //
// This program is distributed in the hope that it will be useful,         //
// but WITHOUT ANY WARRANTY; without even the implied warranty of          //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
// GNU General Public License for more details.                            //
//                                                                         //
// You should have received a copy of the GNU General Public License       //
// along with this program; if not, write to the Free Software Foundation, //
// Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.         //
/////////////////////////////////////////////////////////////////////////////

#ifndef _THING_H_
#define _THING_H_

#include "Definitions.h"
#include "Position.h"

//class Creature;
class Player;
class Item;

/* A 'Thing' object should not ever be created */

class Thing
{
public:

    Thing ( void );

    virtual Player* GetPlayer ( void );
    virtual Item* GetItem ( void );

    Position_t Position;
};

#endif

Reply With Quote
  #12  
Old October 1st, 2006, 09:30 PM
Java Robin XTF Java Robin XTF is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: New York City
Posts: 25 Java Robin XTF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 18 sec
Reputation Power: 0
Tile.cpp
Code:
/////////////////////////////////////////////////////////////////////////////
// The New OTServ - an opensource server for the MMORPG Tibia              //
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or           //
// modify it under the terms of the GNU General Public License             //
// as published by the Free Software Foundation; either version 2          //
// of the License, or (at your option) any later version.                  //
//                                                                         //
// This program is distributed in the hope that it will be useful,         //
// but WITHOUT ANY WARRANTY; without even the implied warranty of          //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
// GNU General Public License for more details.                            //
//                                                                         //
// You should have received a copy of the GNU General Public License       //
// along with this program; if not, write to the Free Software Foundation, //
// Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.         //
/////////////////////////////////////////////////////////////////////////////

#include "Tile.h"

UInt16 Tile::GetGroundID ( void ) const
{
    return _GroundIdentifier;
}

void Tile::SetGroundID ( UInt16 GroundID )
{
    _GroundIdentifier = GroundID;
}

Boolean Tile::isProtectionZone ( void ) const
{
    return (_State & TS_PROTECTION_ZONE);
}

Boolean Tile::isBurning ( void ) const
{
    return (_State & TS_BURNING);
}

Boolean Tile::isEnergized ( void ) const
{
    return (_State & TS_ENERGIZED);
}

Boolean Tile::isPoisoned ( void ) const
{
    return (_State & TS_POISONED);
}

Boolean Tile::isTeleport ( void ) const
{
    return (_State & TS_TELEPORT);
}

void Tile::SetProtectionZone ( void )
{
    _State |= TS_PROTECTION_ZONE;
}

void Tile::SetBurn ( void )
{
    _State |= TS_BURNING;
}

void Tile::SetEnergy ( void )
{
    _State |= TS_ENERGIZED;
}

void Tile::SetPoison ( void )
{
    _State |= TS_POISONED;
}

void Tile::SetTeleport ( void )
{
    _State |= TS_TELEPORT;
}

void Tile::PlaceCreature ( Player* Someone )
{
    Players.push_back ( Someone );
}

bool Tile::RemoveCreature ( Player* player )
{
    if (!Players.empty())
    {
        TilePlayerList::iterator LPPlayer = Players.begin();
        //playerlist declare;
        do
        {
            if ( (*LPPlayer) == player )
            {
                Players.erase ( LPPlayer );
                //remove player from the list;
                return true;
            }

            ++LPPlayer;
        }
        while ( LPPlayer != Players.end() );
    }

    return false;
}

void Tile::PlaceItem ( Item* Something )
{
    DownItems.push_back ( Something );
}

Boolean Tile::RemoveItem ( Item* Something )
{
    if ( !DownItems.empty() )
    {
        ItemList::iterator LPItem = DownItems.begin();

        do
        {
            if ( (*LPItem) == Something )
            {
                DownItems.erase ( LPItem );

                return true;
            }

            ++LPItem;
        }
        while ( LPItem != DownItems.end() );
    }

    return false;
}

UInt32 Tile::GetThingStackPosition ( Thing* Something )
{
    UInt32 StackPosition = 0;

    if ( Something->GetPlayer() )
    {
        if ( !Players.empty() )
        {
            TilePlayerList::iterator LPPlayer = Players.begin();

            do
            {
                StackPosition++;

                /*if ( (*LPPlayer) == Something )
                {
                    return StackPosition;
                }*/

                ++LPPlayer;
            }
            while ( LPPlayer != Players.end() );
        }
    }
    else
    {
        StackPosition += Players.size();
    }

    if ( Something->GetItem() )
    {
        if ( !Players.empty() )
        {
            TilePlayerList::iterator LPPlayer = Players.begin();

            do
            {
                StackPosition++;

                /*if ( (*LPPlayer) == Something )
                {
                    return StackPosition;
                }*/

                ++LPPlayer;
            }
            while ( LPPlayer != Players.end() );
        }
    }
    else
    {
        StackPosition += Players.size();
    }
        

    throw;
}

TilePlayerList Tile::GetCreatureStackPosition ( Player* Someone )
{
    if ( !Players.empty() )
    {
        UInt32 StackPosition = 1;

        TilePlayerList::iterator LPCreature = Players.begin();

        do
        {
            if ( (*LPCreature) == Someone )
            {
                StackPosition /* + TopItems.size() */;
            }

            ++StackPosition;

            ++LPCreature;
        }
        while ( LPCreature != Players.end() );
    }

    throw;
}

Tile.h
Code:
/////////////////////////////////////////////////////////////////////////////
// The New OTServ - an opensource server for the MMORPG Tibia              //
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or           //
// modify it under the terms of the GNU General Public License             //
// as published by the Free Software Foundation; either version 2          //
// of the License, or (at your option) any later version.                  //
//                                                                         //
// This program is distributed in the hope that it will be useful,         //
// but WITHOUT ANY WARRANTY; without even the implied warranty of          //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
// GNU General Public License for more details.                            //
//                                                                         //
// You should have received a copy of the GNU General Public License       //
// along with this program; if not, write to the Free Software Foundation, //
// Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.         //
/////////////////////////////////////////////////////////////////////////////

#ifndef _TILE_H_
#define _TILE_H_

#include <vector>

#include "Definitions.h"
#include "Thing.h"
#include "Items.h"

typedef std::vector<Player*> TilePlayerList;
typedef std::vector<Item*> ItemList;

enum TileState_t
{
    TS_NONE            = 0x00,

    TS_PROTECTION_ZONE = 0x01,

    TS_BURNING         = 0x02,
    TS_ENERGIZED       = 0x03,
    TS_POISONED        = 0x04,

    TS_TELEPORT        = 0x05
};

class Tile
{
public:

    Tile ( void )
    : _GroundIdentifier ( 0 ), _State ( TS_NONE ), X ( 31 ), Y ( 31 ), Z ( 7 )
    {
    }

    Tile ( UInt16 GroundIdentifier, UInt16 X, UInt16 Y, Byte Z )
    : _GroundIdentifier ( GroundIdentifier ), _State ( TS_NONE ), X ( X ), Y ( Y ), Z ( Z )
    {
    }

    ~Tile ( void )
    {
    }

    UInt16 GetGroundID ( void ) const;

    void SetGroundID ( UInt16 Identifier );

    Boolean isProtectionZone ( void ) const;

    Boolean isBurning ( void ) const;
    Boolean isEnergized ( void ) const;
    Boolean isPoisoned ( void ) const;

    Boolean isTeleport ( void ) const;

    void SetProtectionZone ( void );

    void SetBurn ( void );
    void SetEnergy ( void );
    void SetPoison ( void );

    void SetTeleport ( void );

    void PlaceCreature ( Player* );
    bool RemoveCreature ( Player* );

    void PlaceItem ( Item* );
    Boolean RemoveItem ( Item* );

    UInt32 GetThingStackPosition ( Thing* );
    TilePlayerList GetCreatureStackPosition ( Player* );

    TilePlayerList Players;
    ItemList DownItems;

    const UInt16 X;
    const UInt16 Y;
    const Byte Z;

protected:

    UInt16 _GroundIdentifier;
    UInt16 _State;
};

#endif

Reply With Quote
  #13  
Old October 1st, 2006, 09:34 PM
Java Robin XTF Java Robin XTF is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: New York City
Posts: 25 Java Robin XTF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 18 sec
Reputation Power: 0
Tools.cpp
Code:
//////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
//////////////////////////////////////////////////////////////////////
// Various functions.
//////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//////////////////////////////////////////////////////////////////////

#include "Tools.h"

void toLowerCaseString(std::string& source)
{
	std::transform(source.begin(), source.end(), source.begin(), tolower);
}

bool readXMLInteger(xmlNodePtr node, const char* tag, int& value)
{
	char* nodeValue = (char*)xmlGetProp(node, (xmlChar*)tag);
	if(nodeValue){
		value = atoi(nodeValue);
		xmlFreeOTSERV(nodeValue);
		return true;
	}

	return false;
}

bool readXMLString(xmlNodePtr node, const char* tag, std::string& value)
{
	char* nodeValue = (char*)xmlGetProp(node, (xmlChar*)tag);
	if(nodeValue){
		value = nodeValue;
		xmlFreeOTSERV(nodeValue);
		return true;
	}

	return false;
}

int random_range(int lowest_number, int highest_number)
{
	if(lowest_number > highest_number){
		int nTmp = highest_number;
		highest_number = lowest_number;
		lowest_number = nTmp;
	}

	double range = highest_number - lowest_number + 1;
	return lowest_number + int(range * rand()/(RAND_MAX + 1.0));
}

Tools.h
Code:
//////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//////////////////////////////////////////////////////////////////////

#ifndef __OTSERV_TOOLS_H__
#define __OTSERV_TOOLS_H__

#include "definitions.h"

#include <string>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>

#include <libxml/parser.h>

void toLowerCaseString(std::string& source);

bool readXMLInteger(xmlNodePtr node, const char* tag, int& value);
bool readXMLString(xmlNodePtr node, const char* tag, std::string& value);

int random_range(int lowest_number, int highest_number);

#endif

That's all that there is..
Hope someone can help now.

Reply With Quote
  #14  
Old October 1st, 2006, 11:30 PM
Java Robin XTF Java Robin XTF is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: New York City
Posts: 25 Java Robin XTF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 18 sec
Reputation Power: 0
Someone please look at this thread =/

Reply With Quote
  #15  
Old October 2nd, 2006, 03:59 AM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
Hey Robin,
I'm not home now, but as soon as I go, I'll look at it and see what's going on.

Costas

Reply With Quote
  #16  
Old October 2nd, 2006, 04:25 AM
Java Robin XTF Java Robin XTF is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: New York City
Posts: 25 Java Robin XTF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 18 sec
Reputation Power: 0
Alright thanks..
I already private messaged a few others to help out..
I'm going to have this project on sourceforge soon to make modifications easier to handle..
Any help at all is appreciated.

Reply With Quote
  #17  
Old October 2nd, 2006, 06:17 AM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
Hey, what the .... You wrote all that code and you can't just add a function to log in a player. Well, I don't think I CAN help, but I'll try!

Note: I can't see any private messages! - please send them so I can understand what you're saying

Costas

Reply With Quote
  #18  
Old October 3rd, 2006, 09:05 PM
Java Robin XTF Java Robin XTF is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: New York City
Posts: 25 Java Robin XTF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 18 sec
Reputation Power: 0
The player can log on, just can't turn, walk, or speak.
I'll send you sources which include these but the base code is formatted differently. Still I believe if you look at it you could get some basic idea in a couple of minutes.
I'll add a link later.

Reply With Quote
  #19  
Old October 4th, 2006, 10:01 AM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
OK! I'll try to understand what you're saying.

Reply With Quote
  #20  
Old October 7th, 2006, 04:38 AM
Java Robin XTF Java Robin XTF is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: New York City
Posts: 25 Java Robin XTF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 18 sec
Reputation Power: 0
Alright here is a link to an open source project for OpenTibia servers like the one we're trying to make except filled with too much "junk" but the coding for what we're trying to do is perfect.

http://opentibia.cvs.sourceforge.ne...ev=revbattlesys

We're trying to make it work for the 7.6 client so this link might be more "direct"


Binaries: Sql
[URL=http://rapidshare.de/files/35781557/Oct7SQLrevbat.rar

XML:
http://rapidshare.de/files/35781558/Oct7XMLrevbat.rar

Reply With Quote
  #21  
Old October 8th, 2006, 09:08 AM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
Hey, Robin
There are to much files! Why don't you zip or rar them and send them to my email(I'll privately send it you--I'll wait for your OK)? OK?

Reply With Quote
  #22  
Old October 8th, 2006, 02:17 PM
Java Robin XTF Java Robin XTF is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: New York City
Posts: 25 Java Robin XTF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 18 sec
Reputation Power: 0
I posted it as a .rar in my first post -_-!!!!!!
OK
http://www.megaupload.com/?d=17PO131N
http://www.megaupload.com/?d=17PO131N
OK
Zubin31337@gmail.com is my E-mail.

Reply With Quote
  #23  
Old October 9th, 2006, 12:24 PM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
Hey Robin, I sent you an email!!!

Reply With Quote
  #24  
Old October 14th, 2006, 12:46 AM
Java Robin XTF Java Robin XTF is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: New York City
Posts: 25 Java Robin XTF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 18 sec
Reputation Power: 0
Alright..
Latest source files with
all the features I wanted to add can be found here:
http://rapidshare.de/files/36603001/own_source__ot_.rar.html
http://rapidshare.de/files/36603001...e__ot_.rar.html
I became tired of waiting >_<
Please post any bugs/ patches on this thread.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > C++ Need help adding a few functions/features..


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap