Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Private Server > CO2 PServer Guides & Releases
You last visited: Today at 22:08

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Release] Extremely basic (but working/bugless) C# Source

Discussion on [Release] Extremely basic (but working/bugless) C# Source within the CO2 PServer Guides & Releases forum part of the CO2 Private Server category.

Closed Thread
 
Old 01/26/2009, 08:59   #31
 
elite*gold: 20
Join Date: Apr 2008
Posts: 2,281
Received Thanks: 912
Here's a simple account creator.

Just throw it in your Accounts folder and make your account =P

(What? I was bored =P)
Attached Files
File Type: zip FlatFile_AccountCreator.zip (7.0 KB, 195 views)
kinshi88 is offline  
Thanks
6 Users
Old 01/26/2009, 18:02   #32
 
InfamousNoone's Avatar
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,882
@ranny:
thanks, will be included in rev3

@pete:

Code:
                    case "@scroll":
                        {
                            switch (args[1].ToLower())
                            {
                                case "tc":
                                    Client.Teleport(1002, 431, 379);
                                    break;
                                case "pc":
                                    Client.Teleport(1011, 190, 271);
                                    break;
                                case "am":
                                    Client.Teleport(1020, 567, 576);
                                    break;
                                case "dc":
                                    Client.Teleport(1000, 500, 650);
                                    break;
                                case "bi":
                                    Client.Teleport(1015, 723, 573);
                                    break;
                                case "ma":
                                    Client.Teleport(1036, 200, 200);
                                    break;
                                case "arena":
                                    Client.Teleport(1005, 52, 69);
                                    break;
                            }
                            break;
                        }
InfamousNoone is offline  
Thanks
5 Users
Old 01/30/2009, 04:25   #33
 
elite*gold: 0
Join Date: Feb 2008
Posts: 1,590
Received Thanks: 154
Attached Files
File Type: txt Item Information.txt (4.7 KB, 172 views)
tao4229 is offline  
Thanks
3 Users
Old 01/30/2009, 05:35   #34
 
punkmak2's Avatar
 
elite*gold: 0
Join Date: Jun 2005
Posts: 27
Received Thanks: 49
Infamous are you aware of the Screen.Reload bug. For some reason it doesn't always seem to load all the Characters weirdly enough or remove them once their disconnected, lol.
It affects the Team Dismissing once the team leader logs off or if a Team Member disconnects he is removed from the team. Because once the Team Member connects to the game again and the Team Leader re-invites the Player it's thinking it's the old Client that was previously connected. Therefore still thinking that the old Client is in a Team... lol Sorry if i've confused you.


Change Direction Implementation.

1) In Data Packet.cs add a new public const ushort
Code:
             ChangeDirection = 79,
2) In PacketProcessor.cs, under public static void Process, add to case 1010:
Code:
                            case DataPacket.ChangeDirection:
                                ChangeDirection(Client, cPacket);
                                break;
3) In PacketProcessor.cs, in public class PacketProcessor. Add the follow code.
Code:
        public static void ChangeDirection(GameClient Client, DataPacket Packet)
        {
            ushort Direction = (ushort)(Packet.wParam3);
            ushort Client_X = (ushort)(Packet.wParam1);
            ushort Client_Y = (ushort)(Packet.wParam2);

            if (Enum.IsDefined(typeof(ConquerAngle), (ConquerAngle)Direction))
            {
                if (Client.Entity.X == Client_X && Client.Entity.Y == Client_Y)
                {
                    Client.Entity.Facing = (ConquerAngle)Direction;
                    Packet.UID = Client.Entity.UID;
                    Client.SendScreen(Packet, false);
                }
            }
            else
                Client.Socket.Disconnect(); // INVALID_DIRECTION (No Such Facing Direction)
        }


Action Implementation.

1) In Data Packet.cs add a new public const ushort
Code:
             ChangeAction = 81,
2) In PacketProcessor.cs, under public static void Process, add to case 1010:
Code:
                            case DataPacket.ChangeAction:
                                ChangeAction(Client, cPacket);
                                break;
3) In PacketProcessor.cs, in public class PacketProcessor. Add the follow code.
Code:
public static void ChangeAction(GameClient Client, DataPacket Packet)
        {
            ushort Action = (ushort)(Packet.dwParam);
            ushort Client_X = (ushort)(Packet.wParam1);
            ushort Client_Y = (ushort)(Packet.wParam2);

            if (Enum.IsDefined(typeof(ConquerAction), (ConquerAction)Action))
            {
                if (Client.Entity.X == Client_X && Client.Entity.Y == Client_Y)
                {
                    Client.Entity.Action = (ConquerAction)Action;
                    Packet.UID = Client.Entity.UID;
                    Client.SendScreen(Packet, false);
                }
            }
            else
                Client.Socket.Disconnect(); // INVALID_ACTION (No Such Action)
        }


Change PK Mode Implementation.

1) In Data Packet.cs add a new public const ushort
Code:
             ChangePkMode = 96,
2) In PacketProcessor.cs, under public static void Process, add to case 1010:
Code:
                            case DataPacket.ChangePkMode:
                                ChangePkMode(Client, cPacket);
                                break;
3) In PacketProcessor.cs, in public class PacketProcessor. Add the follow code.
Code:
        public static void ChangePkMode(GameClient Client, DataPacket Packet)
        {
            ushort Client_PkMode = (ushort)(Packet.dwParam);

            if (Enum.IsDefined(typeof(PkMode), (PkMode)Client_PkMode))
            {
                Client.Entity.PkMode = (PkMode)Client_PkMode;
                Client.Send(Packet);
            }
            else
                Client.Socket.Disconnect(); // INVALID_PK_MODE (No Such Pk Mode)
        }

4) In IEntity.cs add a new public enum
Code:
public enum PkMode : byte
    {
        PK = 0,
        Peace = 1,
        Team = 2,
        Capture = 3
    }
5) In IEntity.cs, under public class IEntity : IBaseEntity, IMapObject add the following code.
Code:
        private ushort m_PkMode;
6) In IEntity.cs, under public class IEntity : IBaseEntity, IMapObject add the following code.
Code:
public PkMode PkMode
        {
            get
            {
                return (PkMode)this.m_PkMode;
            }
            set
            {
                this.m_PkMode = (ushort)value;
            }
        }
punkmak2 is offline  
Thanks
7 Users
Old 01/30/2009, 06:51   #35
 
punkmak2's Avatar
 
elite*gold: 0
Join Date: Jun 2005
Posts: 27
Received Thanks: 49
Sorry for double posting but rather then confuse everyone I'd like to just have the Team code in one thread.

Teams Implementation.
*NOTE* I still haven't implemented Team Leader Location Updating on MiniMap or Team Members HP. I will work on that Later.

1) Create a new Class file in the folder Interfaces called "ITeam.cs"

2) Replace all the code in newly created file ITeam.cs with the code below.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConquerServer_Basic
{
    public interface ITeam
    {
        GameClient Leader { get; set; }
        GameClient[] Members { get; set; }
        bool ForbidTeam { get; set; }
        bool PickupGold { get; set; }
        bool PickupItems { get; set; }
    }

    public class Team : ITeam
    {
        private GameClient _Leader;
        private GameClient[] _Members = new GameClient[4];
        private bool _ForbidTeam = false;
        private bool _PickupGold = true;
        private bool _PickupItems = false;

        public Team(GameClient Leader) { _Leader = Leader; }

        public GameClient Leader
        {
            get
            {
                return _Leader;
            }

            set
            {
                _Leader = value;
            }
        }
        public GameClient[] Members
        {
            get
            {
                return _Members;
            }

            set
            {
                _Members = value;
            }
        }
        public bool ForbidTeam
        {
            get
            {
                return _ForbidTeam;
            }

            set
            {
                _ForbidTeam = value;
            }
        }
        public bool PickupGold
        {
            get
            {
                return _PickupGold;
            }

            set
            {
                _PickupGold = value;
            }
        }
        public bool PickupItems
        {
            get
            {
                return _PickupItems;
            }

            set
            {
                _PickupItems = value;
            }
        }
        public bool isTeamFull()
        {
            foreach (GameClient Player in _Members)
            {
                if (Player == null)
                    return false;
            }
            return true;
        }
        public void SendPacketToTeam(byte[] Packet, GameClient Client, bool SendToSelf)
        {
            foreach (GameClient Player in _Members)
            {
                if (Player != null)
                {
                    if (Player == Client)
                    {
                        if (SendToSelf)
                            Player.Send(Packet);
                    }
                    else
                        Player.Send(Packet);
                }
            }
            if (Leader == Client)
            {
                if (SendToSelf)
                    Leader.Send(Packet);
            }
            else
                Leader.Send(Packet);
        }
        public void SendPacketToTeam(byte[] Packet)
        {
            foreach (GameClient Player in _Members)
            {
                if (Player != null)
                    Player.Send(Packet);
            }
            Leader.Send(Packet);
        }
        public void TeamClose()
        {
            foreach (GameClient Player in _Members)
            {
                if (Player != null)
                    Player.Entity.Team = null;
            }
        }
        public void AddMember(GameClient Client)
        {
            if (!isTeamFull())
            {
                for (int Counter = 0; Counter < _Members.Length; Counter++)
                {
                    if (_Members[Counter] == null)
                    {
                        _Members[Counter] = Client;
                        Client.Send(PacketBuilder.PlayerJoinTeam(_Leader));
                        foreach (GameClient Player in _Members)
                        {
                            if (Player != null)
                                Client.Send(PacketBuilder.PlayerJoinTeam(Player));
                        }
                        SendPacketToTeam(PacketBuilder.PlayerJoinTeam(Client));
                        break;
                    }
                }
            }
        }
        public void RemoveMember(uint UID, bool Kicked)
        {
            for (int Counter = 0; Counter < _Members.Length; Counter++)
            {
                if (_Members[Counter].Entity.UID == UID)
                {
                    if(Kicked)
                        SendPacketToTeam(new TeamPacket(TeamPacket.Kick, _Members[Counter].Entity.UID).Serialize());
                    else
                        SendPacketToTeam(new TeamPacket(TeamPacket.ExitTeam, _Members[Counter].Entity.UID).Serialize());
                    _Members[Counter].Entity.Team = null;
                    string KickName = _Members[Counter].Entity.Name;
                    _Members[Counter] = null;
                    if(Kicked)
                        SendPacketToTeam(new MessagePacket(KickName + " was kicked from the team!", 0xFFFFFF, MessagePacket.TopLeft).Serialize());
                    else
                        SendPacketToTeam(new MessagePacket(KickName + " has left the team!", 0xFFFFFF, MessagePacket.TopLeft).Serialize());
                    break;
                }
            }
        }
    }
}
3) Create a new Class file in the folders Networking/Packets called "Team Packets.cs"

4) Replace all the code in newly created file Team Packets.cs with the code below.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConquerServer_Basic
{
    public class TeamPacket : IClassPacket
    {
        public const ushort
             Create = 0,
             JoinRequest = 1,
             ExitTeam = 2,
             AcceptInvitation = 3,
             InviteRequest = 4,
             AcceptJoinRequest = 5,
             Dismiss = 6,
             Kick = 7,
             ForbidJoining = 8,
             UnforbidJoining = 9,
             LootMoneyOff = 10,
             LootMoneyOn = 11,
             LootItemsOff = 12,
             LootItemsOn = 13;

        
        private byte[] Packet;

        public TeamPacket()
        {
            Packet = new byte[12];
            PacketBuilder.WriteUInt16(12, Packet, 0);
            PacketBuilder.WriteUInt16(1023, Packet, 2);
        }

        public TeamPacket(uint _ID, uint _PlayerUID)
        {
            Packet = new byte[12];
            PacketBuilder.WriteUInt16(12, Packet, 0);
            PacketBuilder.WriteUInt16(1023, Packet, 2);
            ID = _ID;
            PlayerUID = _PlayerUID;
        }

        public uint ID
        {
            get { return BitConverter.ToUInt32(Packet, 4); }
            set { PacketBuilder.WriteUInt32(value, Packet, 4); }
        }

        public uint PlayerUID
        {
            get { return BitConverter.ToUInt32(Packet, 8); }
            set { PacketBuilder.WriteUInt32(value, Packet, 8); }
        }

        public byte[] Serialize()
        {
            return Packet;
        }
        public void Deserialize(byte[] Bytes)
        {
            Packet = Bytes;
        }
    }
}
5) In PacketProcessor.cs, under public static void Process, add a new case
Code:
case 1023:
                    {
                        Team(Client, Packet);
                        break;
                    }
6) In PacketProcessor.cs, in public class PacketProcessor. Add the follow code.
Code:
        public static void Team(GameClient Client, byte[] Packet)
        {
            TeamPacket cPacket = new TeamPacket();
            SyncPacket sync;
            cPacket.Deserialize(Packet);
            switch (cPacket.ID)
            {
                case TeamPacket.Create:
                    if (Client.Entity.Team == null)
                    {
                        Client.Entity.Team = new Team(Client);

                        Client.Send(Packet);
                        Client.Entity.StatusFlag += 64;
                        sync = new SyncPacket(1);
                        sync.UID = Client.Identifier;
                        sync[0] = SyncPacket.Data.Create(SyncPacket.RaiseFlag, Client.Entity.StatusFlag);
                        Client.SendScreen(sync, true);
                    }
                    break;

                case TeamPacket.Dismiss:
                    if (Client.Entity.Team != null)
                    {
                        Client.Entity.Team.SendPacketToTeam(Packet);
                        Client.Entity.Team.TeamClose();
                        Client.Entity.Team = null;

                        Client.Entity.StatusFlag -= 64;
                        sync = new SyncPacket(1);
                        sync.UID = Client.Identifier;
                        sync[0] = SyncPacket.Data.Create(SyncPacket.RaiseFlag, Client.Entity.StatusFlag);
                        Client.SendScreen(sync, true);
                    }
                    break;

                case TeamPacket.InviteRequest:
                    if (Client.Entity.Team != null)
                    {
                        if (Client.Entity.Team.Leader == Client)
                        {
                            if (!Client.Entity.Team.isTeamFull())
                            {
                                foreach (IMapObject obj in Client.Screen.Objects)
                                {
                                    if (obj.MapObjType == MapObjectType.Player)
                                    {
                                        if ((obj.Owner as GameClient).Entity.UID == cPacket.PlayerUID)
                                        {
                                            if ((obj.Owner as GameClient).Entity.Team == null)
                                            {
                                                cPacket.PlayerUID = Client.Entity.UID;
                                                (obj.Owner as GameClient).Send(cPacket.Serialize());
                                            }
                                            else
                                                Client.Send(new MessagePacket((obj.Owner as GameClient).Entity.Name + " is in another Team!", 0xFFFFFF, MessagePacket.TopLeft).Serialize());
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;

                case TeamPacket.JoinRequest:
                    if (Client.Entity.Team == null)
                    {
                        foreach (IMapObject obj in Client.Screen.Objects)
                        {
                            if (obj.MapObjType == MapObjectType.Player)
                            {
                                if ((obj.Owner as GameClient).Entity.UID == cPacket.PlayerUID)
                                {
                                    if ((obj.Owner as GameClient).Entity.Team != null)
                                    {
                                        if (!(obj.Owner as GameClient).Entity.Team.ForbidTeam)
                                        {
                                            if (!(obj.Owner as GameClient).Entity.Team.isTeamFull())
                                            {
                                                cPacket.PlayerUID = Client.Entity.UID;
                                                (obj.Owner as GameClient).Send(cPacket.Serialize());
                                            }
                                            else
                                                Client.Send(new MessagePacket("Team is full!", 0xFFFFFF, MessagePacket.TopLeft).Serialize());
                                        }
                                        else
                                            Client.Send(new MessagePacket("The team doesn't accept new members.", 0xFFFFFF, MessagePacket.TopLeft).Serialize());
                                    }
                                    else
                                        Client.Send(new MessagePacket((obj.Owner as GameClient).Entity.Name + " has no Team!", 0xFFFFFF, MessagePacket.TopLeft).Serialize());
                                }
                            }
                        }
                    }
                    break;

                case TeamPacket.Kick:
                    if (Client.Entity.Team != null)
                    {
                        if (Client.Entity.Team.Leader == Client)
                        {
                            Client.Entity.Team.SendPacketToTeam(Packet);
                            Client.Entity.Team.RemoveMember(cPacket.PlayerUID, true);
                        }
                    }
                    break;

                case TeamPacket.ForbidJoining:
                    if (Client.Entity.Team != null)
                    {
                        if (Client.Entity.Team.Leader == Client)
                        {
                            Client.Entity.Team.ForbidTeam = true;
                        }
                    }
                    break;

                case TeamPacket.UnforbidJoining:
                    if (Client.Entity.Team != null)
                    {
                        if (Client.Entity.Team.Leader == Client)
                        {
                            Client.Entity.Team.ForbidTeam = false;
                        }
                    }
                    break;

                case TeamPacket.LootMoneyOn:
                    if (Client.Entity.Team != null)
                    {
                        if (Client.Entity.Team.Leader == Client)
                        {
                            Client.Entity.Team.PickupGold = true;
                        }
                    }
                    break;

                case TeamPacket.LootMoneyOff:
                    if (Client.Entity.Team != null)
                    {
                        if (Client.Entity.Team.Leader == Client)
                        {
                            Client.Entity.Team.PickupGold = false;
                        }
                    }
                    break;

                case TeamPacket.LootItemsOn:
                    if (Client.Entity.Team != null)
                    {
                        if (Client.Entity.Team.Leader == Client)
                        {
                            Client.Entity.Team.PickupItems = true;
                        }
                    }
                    break;

                case TeamPacket.LootItemsOff:
                    if (Client.Entity.Team != null)
                    {
                        if (Client.Entity.Team.Leader == Client)
                        {
                            Client.Entity.Team.PickupItems = false;
                        }
                    }
                    break;

                case TeamPacket.ExitTeam:
                    if (Client.Entity.Team != null)
                    {
                        if (Client.Entity.Team.Leader != Client)
                        {
                            Client.Entity.Team.SendPacketToTeam(Packet);
                            Client.Entity.Team.RemoveMember(cPacket.PlayerUID, false);
                        }
                    }
                    break;

                case TeamPacket.AcceptInvitation:
                    if (Client.Entity.Team == null)
                    {
                        foreach (IMapObject obj in Client.Screen.Objects)
                        {
                            if (obj.MapObjType == MapObjectType.Player)
                            {
                                if ((obj.Owner as GameClient).Entity.UID == cPacket.PlayerUID)
                                {
                                    cPacket.PlayerUID = Client.Entity.UID;
                                    Team PlayersTeam = (obj.Owner as GameClient).Entity.Team;
                                    if (PlayersTeam != null)
                                    {
                                        if (!PlayersTeam.isTeamFull())
                                        {
                                            PlayersTeam.AddMember(Client);
                                            Client.Entity.Team = PlayersTeam;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;

                case TeamPacket.AcceptJoinRequest:
                    if (Client.Entity.Team != null)
                    {
                        foreach (IMapObject obj in Client.Screen.Objects)
                        {
                            if (obj.MapObjType == MapObjectType.Player)
                            {
                                if ((obj.Owner as GameClient).Entity.UID == cPacket.PlayerUID)
                                {
                                    cPacket.PlayerUID = Client.Entity.UID;
                                    Team PlayersTeam = (obj.Owner as GameClient).Entity.Team;
                                    if (PlayersTeam == null)
                                    {
                                        if (!Client.Entity.Team.isTeamFull())
                                        {
                                            Client.Entity.Team.AddMember((obj.Owner as GameClient));
                                            (obj.Owner as GameClient).Entity.Team = Client.Entity.Team;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
            }
        }

7) In IEntity.cs, under public class IEntity : IBaseEntity, IMapObject add the following code.
Code:
        private Team m_Team;

8) In IEntity.cs, under public class IEntity : IBaseEntity, IMapObject add the following code.
Code:
        public Team Team
        {
            get
            {
                return this.m_Team;
            }
            set
            {
                this.m_Team = value;
            }
        }
9) In Program.cs replace public static void GameDisconnect(HybridWinsockClient Sender, object param) with the following code:
Code:
public static void GameDisconnect(HybridWinsockClient Sender, object param)
        {
            GameClient Client = (GameClient)Sender.Wrapper;
            if (Client != null)
            {
                if (Client.AuthPhase >= AuthPhases.GameComplete)
                {
                    try
                    {
                        if (Client.Entity.Team != null)
                        {
                            if (Client.Entity.Team.Leader == Client)
                            {
                                Client.Entity.Team.SendPacketToTeam(new TeamPacket(TeamPacket.Dismiss, Client.Entity.UID).Serialize());
                                Client.Entity.Team.TeamClose();
                            }
                            else
                            {
                                Client.Entity.Team.RemoveMember(Client.Entity.UID, false);
                                Client.Entity.Team = null;
                            }
                        }
                        DataPacket remove = new DataPacket(true);
                        remove.UID = Client.Identifier;
                        remove.ID = DataPacket.RemoveEntity;
                        Client.SendScreen(remove, false);
                    }
                    finally
                    {
                        Database.SaveCharacter(Client);
                        Kernel.GamePool.ThreadSafeRemove<uint, GameClient>(Client.Identifier);
                    }
                }
            }
        }
punkmak2 is offline  
Thanks
4 Users
Old 02/01/2009, 01:31   #36
 
InfamousNoone's Avatar
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,882
Rev3 *should* be out by tonight if Ranny's team implementation goes smoothly.

Note to Ranny:
The "Entity" variable's type is also "Entity". I intended to use this class a shared class between both players and monsters (or at least, this is what I do on my main server seeing both monsters, and players share the same spawn packet). Anything that only players have i.e. teams, pkmodes, etc. should be kept strictly in the GameClient class.

Thanks
InfamousNoone is offline  
Thanks
2 Users
Old 02/03/2009, 23:43   #37
 
InfamousNoone's Avatar
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,882
Rev3 Important Issue
Thanks for somewhat bringing this to my attention Kinshi :P

In Database.cs, Find "SaveCharacter", Near the bottom you should see
Code:
            wrtr.Write("Character", "RebornCount", Client.Entity.Reborn);

            SaveCharacter(Client);
This should be changed to
Code:
            wrtr.Write("Character", "RebornCount", Client.Entity.Reborn);

            SaveInventory(Client);
Failing to change this will freeze (somewhat) your server when someone logs out.
InfamousNoone is offline  
Thanks
6 Users
Old 02/04/2009, 01:04   #38
 
© Haydz's Avatar
 
elite*gold: 20
Join Date: Jan 2008
Posts: 1,042
Received Thanks: 252
Use the NextItemUID for item uids
© Haydz is offline  
Thanks
1 User
Old 02/04/2009, 01:44   #39
 
InfamousNoone's Avatar
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,882
Code:
        private static void LoadEquips(GameClient Client)
        {
            IniFile rdr = new IniFile(DatabasePath + @"\Equips\" + Client.Username + ".ini");
            for (sbyte i = 0; i < Client.Equipment.Count; i++)
            {
                ItemDataPacket LoadedEquip;
                if (ItemDataPacket.Parse(rdr.ReadString("Equips", "Item[" + i.ToString() + "]", String.Empty), out LoadedEquip))
                {
                    Client.Equip(LoadedEquip, (ushort)(i + 1));
                }
            }
        }
        private static void SaveEquips(GameClient Client)
        {
            IniFile wrtr = new IniFile(DatabasePath + @"\Equips\" + Client.Username + ".ini");
            lock (Client.Equipment)
            {
                foreach (KeyValuePair<ushort, IConquerItem> DE in Client.Equipment)
                {
                    wrtr.Write("Equips", "Item[" + (DE.Key - 1).ToString() + "]", DE.Value.ToString());
                }
            }
        }
InfamousNoone is offline  
Thanks
7 Users
Old 02/05/2009, 10:52   #40
 
hio77's Avatar
 
elite*gold: 20
Join Date: Jun 2006
Posts: 1,759
Received Thanks: 825
quick question.....

for things like the job npcs or a job command is there certain way the packet should be called or is it just

Code:
Client.Send(PacketBuilder.CharacterInfo(Client));
i know this works well but i just want to make sure its the right way
hio77 is offline  
Thanks
1 User
Old 02/05/2009, 13:07   #41
 
punkmak2's Avatar
 
elite*gold: 0
Join Date: Jun 2005
Posts: 27
Received Thanks: 49
Loading Shops (Shops not added into game yet just the loading of the database)

1) Add a new Interface called "IShop.cs" and replace the code in "IShop.cs" with the code below:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConquerServer_Basic
{
    public interface IShop
    {
        uint ID { get; set; }
        string Name { get; set; }
        ushort Type { get; set; }
        ushort MoneyType { get; set; }
        ushort ItemAmount { get; set; }
        uint[] Items { get; set; }
    }

    public class Shop : IShop
    {
        private uint _ID;
        private string _Name;
        private ushort _Type;
        private ushort _MoneyType;
        private ushort _ItemAmount;
        private uint[] _Items;

        public uint ID { get { return this._ID; } set { this._ID = value; } }
        public string Name { get { return this._Name; } set { this._Name = value; } }
        public ushort Type { get { return this._Type; } set { this._Type = value; } }
        public ushort MoneyType { get { return this._MoneyType; } set { this._MoneyType = value; } }
        public ushort ItemAmount { get { return this._ItemAmount; } set { this._ItemAmount = value; } }
        public uint[] Items { get { return this._Items; } set { this._Items = value; } }
    }

}
2) In Kernel.cs add a new Dictionary to the Kernel Class
Code:
public static Dictionary<uint, IShop> Shops = new Dictionary<uint, IShop>();
3) In Database/Database.cs replace public LoadDatabase() void with the following code:
Code:
public static void LoadDatabase()
        {
#if HYBRID_BUILD
            // This is just so I don't need to include the database in the rar anymore :P
            DatabasePath = @"C:\Users\User\Desktop\Users\ConquerServer_Basic_Rev3\bin\Debug\Database";
#else
            DatabasePath = (Application.StartupPath + @"\Database");
#endif

            foreach (string file in Directory.GetFiles(DatabasePath + "\\cq_npc\\"))
            {
                IniFile cq_npc = new IniFile(file);
                INpc npc = new NpcSpawnPacket();
                npc.UID = cq_npc.ReadUInt32("cq_npc", "id", 0);
                npc.X = cq_npc.ReadUInt16("cq_npc", "cellx", 0);
                npc.Y = cq_npc.ReadUInt16("cq_npc", "celly", 0);
                npc.MapID = cq_npc.ReadUInt16("cq_npc", "mapid", 0);
                npc.Type = cq_npc.ReadUInt16("cq_npc", "lookface", 0);
                npc.Facing = (ConquerAngle)cq_npc.ReadUInt16("cq_npc", "type", 0);
                npc.StatusFlag = cq_npc.ReadUInt16("cq_npc", "sort", 0);

            GetNpcDictionary:
                Dictionary<uint, INpc> npcs;
                if (Kernel.Npcs.TryGetValue(npc.MapID, out npcs))
                {
                    npcs.Add(npc.UID, npc);
                }
                else
                {
                    npcs = new Dictionary<uint, INpc>();
                    Kernel.Npcs.Add(npc.MapID, npcs);
                    goto GetNpcDictionary;
                }
            }


            //Add Shop Items
            IniFile Shop = new IniFile(DatabasePath + "\\Misc\\Shop.ini");
            ushort ShopCount = Shop.ReadUInt16("Header", "Amount", 0);
            for (ushort i = 0; i < ShopCount; i++)
            {
                IShop new_shop = new Shop();
                new_shop.ID = Shop.ReadUInt32("Shop" + i.ToString(), "ID", 0);
                new_shop.Name = Shop.ReadString("Shop" + i.ToString(), "Name", "");
                new_shop.Type = Shop.ReadUInt16("Shop" + i.ToString(), "Type", 1);
                new_shop.MoneyType = Shop.ReadUInt16("Shop" + i.ToString(), "MoneyType", 0);
                uint ItemAmount = Shop.ReadUInt16("Shop" + i.ToString(), "ItemAmount", 0);
                new_shop.Items = new uint[ItemAmount];
                for (ushort e = 0; e < ItemAmount; e++)
                {
                    uint ItemID = Shop.ReadUInt32("Shop" + i.ToString(), "Item" + e.ToString(), 0);
                    new_shop.Items[e] = ItemID;
                }
                Kernel.Shops.Add(new_shop.ID, new_shop);
            }




            Console.WriteLine("Database Loaded");
        }

4) Lastly add the Shop.ini that i've included for download to your Database/Misc folder.
Attached Files
File Type: zip Shop.zip (5.5 KB, 86 views)
punkmak2 is offline  
Thanks
6 Users
Old 02/06/2009, 19:26   #42
 
© Haydz's Avatar
 
elite*gold: 20
Join Date: Jan 2008
Posts: 1,042
Received Thanks: 252
Quote:
Originally Posted by hio77 View Post
quick question.....

for things like the job npcs or a job command is there certain way the packet should be called or is it just

Code:
Client.Send(PacketBuilder.CharacterInfo(Client));
i know this works well but i just want to make sure its the right way
Use the 0x3F9 Packet... Or as it is named in this - "SyncPacket"
© Haydz is offline  
Thanks
1 User
Old 02/08/2009, 13:48   #43
 
punkmak2's Avatar
 
elite*gold: 0
Join Date: Jun 2005
Posts: 27
Received Thanks: 49
1) In Program.cs add:
Code:
public static uint IPAddressToLong(string IPAddr)
        {
            System.Net.IPAddress oIP = System.Net.IPAddress.Parse(IPAddr);
            byte[] byteIP = oIP.GetAddressBytes();


            uint ip = (uint)byteIP[0] << 24;
            ip += (uint)byteIP[1] << 16;
            ip += (uint)byteIP[2] << 8;
            ip += (uint)byteIP[3];

            return ip;
        }

        public static bool CheckIP(string IP)
        {
            uint ClientIPNew = IPAddressToLong(IP);

            foreach (KeyValuePair<uint, IBanCountryIP> pBannedIP in Kernel.CountryBanIP)
            {
                if (ClientIPNew >= pBannedIP.Value.IP_Range1 && ClientIPNew <= pBannedIP.Value.IP_Range2)
                    return false;
            }
            return true;
        }
2) In Program.cs find the public static void AuthConnect and replace it with"
Code:
public static void AuthConnect(HybridWinsockClient Sender, object param)
        {
            if (CheckIP(Sender.Connection.RemoteEndPoint.ToString().Split(':')[0]) && Kernel.CountryBanIP.Count > 0)
                Sender.Wrapper = new AuthClient(Sender);
            else
                Sender.Connection.Disconnect(false);
        }
3) In Database.cs add
Code:
        public static void LoadBannedCountryCodes()
        {
            string[] CountryIP = File.ReadAllLines(DatabasePath + @"\Misc\BannedCountry.ini");
            if (CountryIP.Length > 0)
            {
                for (int i = 0; i < CountryIP.Length; i++)
                {
                    string[] CountryIPRange = CountryIP[i].Split(' ');

                    if (CountryIPRange.Length == 2)
                    {
                        IBanCountryIP IP = new BanCountryIP();
                        IP.ID = (uint)i;
                        IP.IP_Range1 = Program.IPAddressToLong(CountryIPRange[0]);
                        IP.IP_Range2 = Program.IPAddressToLong(CountryIPRange[1]);
                        Kernel.CountryBanIP.Add(IP.ID, IP);
                    }
                }
                Console.WriteLine("Banned Countries has Loaded");
            }
        }
4) in Program.cs find Database.LoadDatabase(); and bellow it add:
Code:
Database.LoadBannedCountryCodes();
5) In Kernel.cs add:
Code:
public static Dictionary<uint, IBanCountryIP> CountryBanIP = new Dictionary<uint, IBanCountryIP>();
6) In the Interfaces Folder create a new class file called "IBanCountryIP.cs". Open IBanCountryIP.cs. Replace the code in the file with:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConquerServer_Basic
{
    public interface IBanCountryIP
    {
        uint ID { get; set; }
        uint IP_Range1 { get; set; }
        uint IP_Range2 { get; set; }
    }

    public class BanCountryIP : IBanCountryIP
    {
        private uint _ID;
        private uint _IP_Range1;
        private uint _IP_Range2;

        public uint ID { get { return this._ID; } set { this._ID = value; } }
        public uint IP_Range1 { get { return this._IP_Range1; } set { this._IP_Range1 = value; } }
        public uint IP_Range2 { get { return this._IP_Range2; } set { this._IP_Range2 = value; } }
    }

}
7 Download the file I've included in this post and extract it into Database/Misc.

8 Lastly you can find all the Countries IP's which you wish to block from connecting to your server on the following site. Simply choose you country, copy all the IP ranges and viola!
Attached Files
File Type: zip BannedCountry.zip (8.2 KB, 36 views)
punkmak2 is offline  
Thanks
6 Users
Old 02/08/2009, 14:50   #44
 
elite*gold: 20
Join Date: Aug 2005
Posts: 1,734
Received Thanks: 1,000
Code:
 private static void SaveInventory(GameClient Client)
        {
            IniFile wrtr = new IniFile(DatabasePath + @"\Inventory\" + Client.Username + ".ini");
            // I use a foreach loop because the Inventory
            // variables length can change at any time technically
            // seeing as it's in sync with the dictionary, but not
            // neccicarly with the function calling it
            // this is rare -- but I've had it happen.
            sbyte i = 0;
            foreach (IConquerItem Item in Client.Inventory)
            {
                wrtr.Write("Inventory", "Item[" + i.ToString() + "]", Item.ToString());
            }
            wrtr.Write("Inventory", "Count", i.ToString());
        }
Problem : variable "i" will stay as 0 since nothing is added to it.
Fix : add "i++" inside the foreach loop

Code:
private static void SaveInventory(GameClient Client)
        {
            IniFile wrtr = new IniFile(DatabasePath + @"\Inventory\" + Client.Username + ".ini");
            // I use a foreach loop because the Inventory
            // variables length can change at any time technically
            // seeing as it's in sync with the dictionary, but not
            // neccicarly with the function calling it
            // this is rare -- but I've had it happen.
            sbyte i = 0;
            foreach (IConquerItem Item in Client.Inventory)
            {
                wrtr.Write("Inventory", "Item[" + i.ToString() + "]", Item.ToString());
                i++;
            } 
            wrtr.Write("Inventory", "Count", i.ToString());
        }
tanelipe is offline  
Thanks
1 User
Old 02/08/2009, 14:50   #45
 
nTL3fTy's Avatar
 
elite*gold: 0
Join Date: Jun 2005
Posts: 692
Received Thanks: 353
On the topic of IP to Country:
nTL3fTy is offline  
Closed Thread


Similar Threads Similar Threads
[Huge-Release] All-In-One Basic NPC Scripts For The 5165 Source!
02/19/2010 - CO2 PServer Guides & Releases - 30 Replies
Well I'm sorry that I spammed the whole forum full of my posts So pro4never and .Ryu gave me the idea of making this All-In-One thread about all my NPC's! THESE ARE UPDATED DAILY! NOTE: TO PEOPLE... SOME OF THE CODES ARE NOT MADE BY ME! I USUALLY JUST FIXED/UPDATED THE BASIC ONES! SORRY I'M LEARNING ON HOW TO CODE! 1. Birth-Island-NPC's(The NPC text is not from "REAL CONQUER" SORRY!...) #region BirthOldGeneralYang case 425: {
[FINAL RELEASE]HuB- Source (BASIC) (Original LOTF easier workable)
11/14/2009 - CO2 PServer Guides & Releases - 25 Replies
#REMOVED
[RELEASE] Basic LOTF Source
09/03/2009 - CO2 PServer Guides & Releases - 17 Replies
hey this is a basic lotf source edited based off shadowco, if you dont like it then dont post here... flames will be told on!!! :D i will tell on you to the mods if you flame What it has... - LuckyTime - Guard - 24/7 GW



All times are GMT +2. The time now is 22:08.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.