You last visited: Today at 16:59
Advertisement
Nobility problem, InfamousNoone Source.
Discussion on Nobility problem, InfamousNoone Source. within the CO2 Private Server forum part of the Conquer Online 2 category.
05/24/2013, 02:46
#1
elite*gold: 0
Join Date: Dec 2012
Posts: 606
Received Thanks: 68
Nobility problem, InfamousNoone Source.
hey guys since my collage classes are starting i need to start getting into more coding and learning stuff so i got InfamousNoone source and it was prty dam good source,
i have been fixing few bugs today garment,guard etc but i got this 1 problem i cannot figure out,
the nobility icon, i know the nobility work i can see the prince in my acc etc but i cannot see the nobility icon at the top so i can donate more or others.
and idk if i am correct or not but i think porblem is comming from here.
Code:
public static implicit operator byte[](NobilityRankPacket packet)
{
int strings_length = 0;
string[] strings = new string[packet.Ranks.Length];
for (int i = 0; i < packet.Ranks.Length; i++)
{
if (packet.Type == NobilityRankType.Icon)
strings[i] = packet.Ranks[i].LocalString;
else if (packet.Type == NobilityRankType.Listings)
strings[i] = packet.Ranks[i].ListingString;
strings_length += strings[i].Length;
}
byte[] data = new byte[33 + strings_length + 8];
fixed (byte* pData = data)
{
FormatHead(pData, data.Length - 8, packet.Type);
*((uint*)(pData + 8)) = packet.Value;
FormatStrings(pData, 28, strings);
PacketBuilder.AppendTQServer(pData, data.Length);
}
return data;
}
here is the full code about nobility but like i said i think the problem is from top and any kind of help will be nice.
Nobility.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using ConquerServer_v2.Packet_Structures;
using ConquerServer_v2.Client;
using ConquerServer_v2.Core;
namespace ConquerServer_v2.Database
{
public class NobilityScoreBoard
{
private static IniFile Nobility;
#if !TOURNAMENT_NOBILITY
private static DateTime LastAccess;
#endif
private static NobilityRank[] m_Ranks;
private static void SyncRealTime()
{
NobilityRankPacket nobility = new NobilityRankPacket();
foreach (GameClient Client in Kernel.Clients)
{
if (Client.Entity.Level >= 70)
{
nobility.Type = NobilityRankType.Icon;
nobility.Value = Client.Entity.UID;
nobility.SingleRank = NobilityScoreBoard.ObtainNobility(Client);
Client.Entity.Nobility = nobility.SingleRank.Rank;
Client.Send(nobility);
}
}
}
public static NobilityRank ObtainNobility(GameClient Client)
{
for (int i = 0; i < m_Ranks.Length; i++)
{
if (m_Ranks[i].UID == Client.Entity.UID)
{
return m_Ranks[i];
}
}
return new NobilityRank(Client.Entity.UID, Client.Entity.Name, NobilityID.None, 0, -1);
}
public static NobilityRank[] QueryRanks()
{
UpdateRanks();
return m_Ranks;
}
#if TOURNAMENT_NOBILITY
#region #if TOURNAMENT_NOBILITY
/* Tournament Nobility Specific */
private static void UpdateRanks()
{
bool Changed;
TournamentProfile[] Profiles = Tournaments.QueryProfiles(out Changed);
if (Changed)
{
NobilityRank[] temp_Ranks = new NobilityRank[Profiles.Length];
for (int i = 0; i < temp_Ranks.Length; i++)
{
temp_Ranks[i].Listing = i;
temp_Ranks[i].Name = Profiles[i].Name;
temp_Ranks[i].Gold = Profiles[i].Amount;
temp_Ranks[i].UID = Profiles[i].UID;
temp_Ranks[i].Rank = ObtainRank(i, temp_Ranks[i].Gold);
}
m_Ranks = temp_Ranks;
SyncRealTime();
}
}
private static NobilityID ObtainRank(int idx, int score)
{
if (idx >= 0 && idx <= 1) // 1st,2nd
return NobilityID.King;
else if (idx >= 2 && idx <= 4) // 3rd~5th
return NobilityID.Prince;
else if (idx >= 5 && idx <= 9) // 6th~10th
return NobilityID.Duke;
if (score >= 150)
return NobilityID.Earl;
if (score >= 100)
return NobilityID.Baron;
if (score >= 50)
return NobilityID.Knight;
return NobilityID.None;
}
#endregion
#else
#region #if !TOURNAMENT_NOBILITY
/* Conquer 2.0 Nobility Specific */
private static NobilityID ObtainRank(int idx, int score)
{
if (idx >= 0 && idx <= 2) // 1st,2nd,3rd
return NobilityID.King;
else if (idx >= 3 && idx <= 14) // 4th to 15th
return NobilityID.Prince;
else if (idx >= 15 && idx <= 49) // 16th to 50th
return NobilityID.Duke;
if (score >= 200000000)
return NobilityID.Earl;
if (score >= 100000000)
return NobilityID.Baron;
if (score >= 30000000)
return NobilityID.Knight;
return NobilityID.None;
}
private static void UpdateRanks()
{
lock (Nobility)
{
DateTime Time = File.GetLastWriteTime(Nobility.FileName);
if (Time != LastAccess)
{
NobilityRank tempProfile = new NobilityRank();
List<NobilityRank> Profiles = new List<NobilityRank>();
if (File.Exists(Nobility.FileName))
{
using (StreamReader rdr = new StreamReader(Nobility.FileName))
{
string Current;
Current = rdr.ReadLine();
if (Current != null)
{
while ((Current = rdr.ReadLine()) != null)
{
int idx = Current.IndexOf('=');
uint.TryParse(Current.Substring(0, idx), out tempProfile.UID);
string[] values = Current.Substring(idx + 1, Current.Length - idx - 1).Split(',');
if (values.Length == 2)
{
tempProfile.Name = values[0];
int.TryParse(values[1], out tempProfile.Gold);
Profiles.Add(tempProfile);
}
}
}
}
}
NobilityRank[] temp_Ranks = Profiles.ToArray();
Array.Sort(temp_Ranks, ScoreComparer.CMP);
for (int i = 0; i < temp_Ranks.Length; i++)
{
temp_Ranks[i].Listing = i;
temp_Ranks[i].Rank = ObtainRank(i, temp_Ranks[i].Gold);
}
m_Ranks = temp_Ranks;
LastAccess = Time;
SyncRealTime();
}
}
}
public static void Donate(GameClient Client, int Amount)
{
lock (Nobility)
{
string Key = Client.Entity.UID.ToString();
string[] value = Nobility.ReadString("Nobility", Key, "", 32).Split(',');
if (value.Length != 2)
value = new string[2];
long donation;
long.TryParse(value[1], out donation);
donation = Math.Min(int.MaxValue, donation + Amount);
value[0] = Client.Entity.Name;
value[1] = donation.ToString();
Nobility.WriteString("Nobility", Key, value[0] + "," + value[1]);
UpdateRanks();
}
}
public static int ToConquerPoints(int Money)
{
const float Ratio = 0.00002f; // ConquerPoints/Money
return (int)Math.Round(Money * Ratio);
}
#endregion
#endif
public static void Init()
{
Nobility = new IniFile(ServerDatabase.Path + @"\Misc\Nobility.ini");
UpdateRanks();
}
}
}
Nobility rank
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConquerServer_v2.Client;
using ConquerServer_v2.Core;
namespace ConquerServer_v2.Packet_Structures
{
public enum NobilityRankType : uint
{
Icon = 0x03,
Listings = 0x02,
Donate = 0x01
}
public struct NobilityRank : IScorable
{
public string Name;
public uint UID;
public int Gold;
public NobilityID Rank;
public int Listing;
public int Score { get { return Gold; } set { Gold = value; } }
public string ListingString
{
get
{
return UID.ToString() + " 0 0 " + Name + " " + Gold.ToString() + " " + ((uint)Rank).ToString() + " " + Listing.ToString();
}
}
public string LocalString
{
get
{
return UID.ToString() + " " + Gold.ToString() + " " + ((uint)Rank).ToString() + " " + Listing.ToString();
}
}
public NobilityRank(CommonEntity Entity, int Gold, int Listing)
{
Name = Entity.Name;
UID = Entity.UID;
Rank = Entity.Nobility;
this.Gold = Gold;
this.Listing = Listing;
}
public NobilityRank(uint UID, string Name, NobilityID Rank, int Gold, int Listing)
{
this.Name = Name;
this.UID = UID;
this.Rank = Rank;
this.Gold = Gold;
this.Listing = Listing;
}
}
public unsafe class NobilityRankPacket
{
public uint Value;
public NobilityRank[] Ranks;
public NobilityRankType Type;
public NobilityRank SingleRank
{
get { return Ranks[0]; }
set
{
Ranks = new NobilityRank[1];
Ranks[0] = value;
}
}
public ushort TotalPages
{
get { fixed (void* ptr = &Value) { return *(((ushort*)ptr) + 1); } }
set { fixed (void* ptr = &Value) { *(((ushort*)ptr) + 1) = value; } }
}
public ushort CurrentPage
{
get { fixed (void* ptr = &Value) { return *(((ushort*)ptr)); } }
set { fixed (void* ptr = &Value) { *(((ushort*)ptr)) = value; } }
}
public static NobilityRankType ID(byte* Ptr)
{
return *((NobilityRankType*)(Ptr + 4));
}
public static ushort GetCurrentPage(byte* Ptr)
{
return *((ushort*)(Ptr + 8));
}
public static int GetSignedValue(byte* Ptr)
{
return *((int*)(Ptr + 8));
}
public static bool PaidInConquerPoints(byte* Ptr)
{
return *((bool*)(Ptr + 16));
}
private static void FormatHead(byte* pData, int Length, NobilityRankType type)
{
*((ushort*)pData) = (ushort)Length;
*((ushort*)(pData + 2)) = 0x810;
*((NobilityRankType*)(pData + 4)) = type;
}
private static void FormatStrings(byte* pData, ushort StartOffset, string[] Strings)
{
pData[StartOffset] = (byte)Strings.Length;
StartOffset++;
for (int i = 0; i < Strings.Length; i++)
{
pData[StartOffset] = (byte)Strings[i].Length;
Strings[i].CopyTo(pData + StartOffset + 1);
StartOffset += (ushort)(Strings[i].Length + 1);
}
}
public static implicit operator byte[](NobilityRankPacket packet)
{
int strings_length = 0;
string[] strings = new string[packet.Ranks.Length];
for (int i = 0; i < packet.Ranks.Length; i++)
{
if (packet.Type == NobilityRankType.Icon)
strings[i] = packet.Ranks[i].LocalString;
else if (packet.Type == NobilityRankType.Listings)
strings[i] = packet.Ranks[i].ListingString;
strings_length += strings[i].Length;
}
byte[] data = new byte[33 + strings_length + 8];
fixed (byte* pData = data)
{
FormatHead(pData, data.Length - 8, packet.Type);
*((uint*)(pData + 8)) = packet.Value;
FormatStrings(pData, 28, strings);
PacketBuilder.AppendTQServer(pData, data.Length);
}
return data;
}
}
}
Rankings
Code:
using System;
using ConquerServer_v2.Core;
using ConquerServer_v2.Client;
using ConquerServer_v2.Database;
using ConquerServer_v2.Packet_Structures;
namespace ConquerServer_v2.Packet_Processor
{
public unsafe partial class PacketProcessor
{
public static void ShowNobilityRankings(GameClient Client, byte* Ptr)
{
const int max_count = 10;
ushort page = Math.Max(NobilityRankPacket.GetCurrentPage(Ptr), (ushort)0);
int position = Math.Max(page * max_count, 0);
NobilityRank[] ranks = NobilityScoreBoard.QueryRanks();
if (position < ranks.Length)
{
int count = Math.Min(max_count, (ranks.Length - position));
NobilityRankPacket Packet = new NobilityRankPacket();
Packet.Type = NobilityRankType.Listings;
Packet.Ranks = new NobilityRank[count+1];
Packet.CurrentPage = page;
Packet.TotalPages = (ushort)(ranks.Length / max_count);
if (ranks.Length % max_count != 0)
Packet.TotalPages++;
Array.Copy(ranks, position, Packet.Ranks, 0, count);
Client.Send(Packet);
}
}
}
}
Donate
Code:
using System;
using ConquerServer_v2.Core;
using ConquerServer_v2.Client;
using ConquerServer_v2.Database;
using ConquerServer_v2.Packet_Structures;
namespace ConquerServer_v2.Packet_Processor
{
public unsafe partial class PacketProcessor
{
public static void DonateNobility(GameClient Client, byte* Ptr)
{
#if !TOURNAMENT_NOBILITY
bool OK = false;
UpdatePacket Update = UpdatePacket.Create();
Update.UID = Client.Entity.UID;
int Amount = NobilityRankPacket.GetSignedValue(Ptr);
if (NobilityRankPacket.PaidInConquerPoints(Ptr))
{
int Amount2 = NobilityScoreBoard.ToConquerPoints(Amount);
if (OK = (Client.ConquerPoints >= Amount2))
{
Client.ConquerPoints -= Amount2;
Update.ID = UpdateID.ConquerPoints;
Update.Value = (uint)Client.ConquerPoints;
}
}
else
{
if (OK = (Client.Money >= Amount))
{
Client.Money -= Amount;
Update.ID = UpdateID.Money;
Update.Value = (uint)Client.Money;
}
}
if (OK)
{
Client.Send(&Update);
NobilityScoreBoard.Donate(Client, Amount);
}
#endif
}
}
}
05/24/2013, 03:18
#2
elite*gold: 28
Join Date: Jun 2010
Posts: 2,226
Received Thanks: 868
Do you know what "implicit operator byte[]" does? If not that's a great place to start.
05/24/2013, 03:22
#3
elite*gold: 0
Join Date: Dec 2012
Posts: 606
Received Thanks: 68
Quote:
Originally Posted by
_DreadNought_
Do you know what "implicit operator byte[]" does? If not that's a great place to start.
found this but no time to read atm
got class to teach after i am back i will read it, thx
05/24/2013, 03:45
#4
elite*gold: 0
Join Date: Dec 2012
Posts: 1,761
Received Thanks: 950
Basically an operator overload of implicit conversions.
Which means you can convert a type implicit into another type. This is different from explicit conversion where you need to specify the type.
Ex: (implicit)
Code:
sbyte signed_byte = 0;
short signed_int16 = signed_byte;
Ex: (explicit)
Code:
short signed_int16 = 0;
sbyte signed_byte = (sbyte)signed_int16 ;
In this case it's an overload of converting NobilityRank (class) into a byte array (byte[])
So you could do:
Code:
NobilityRank rank = new NobilityRank();
// rank.x
// ...
byte[] Packet = rank; // instead of ex. rank.ToArray();
05/24/2013, 10:31
#5
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,885
the packet has changed since then afaik
05/24/2013, 12:43
#6
elite*gold: 0
Join Date: Dec 2012
Posts: 1,761
Received Thanks: 950
Hybrid, I send him mine and it should work, unless it has changed since 5520+
05/24/2013, 22:09
#7
elite*gold: 0
Join Date: Dec 2012
Posts: 606
Received Thanks: 68
i remember that nobility changed, but not sure from what version it was.
Similar Threads
[Help] Impulse Source Nobility Error.
09/14/2012 - CO2 Private Server - 8 Replies
Hey guys I'm finally back and staying.
I've decided to learn the ropes of coding step by step so I took out a fresh copy of the impulse source and began coding on it(just recently). I coded nobility(parts from another reference), but the MySqlReader is giving me problems while I load up the console.
These are my variables at the top:
private DataSet _dataset;
private DataRow _datarow;
private int _row;
const string Table = "table";
Nobility rank 12tails source
05/15/2011 - CO2 Private Server - 0 Replies
hey i want to add this message "Congratulations! <player name> promoted to <rank name>" when people promote Knight,Baron,Earl,Duke and King , I want to appear that message,here is the code I want to add,but I don't know exactly where to add it,I know i need to add it to Nobility.cs or NobilityInfo.cs but I don't know,here is the code:
Network.GamePackets.Message FiveMinutes = new Network.GamePackets.Message("Congratulations! " + client.Entity.Name + "Promoted To" + client.Entity.NobilityRank...
Nobility Hybrids Source (5018+)
09/18/2010 - CO2 PServer Guides & Releases - 8 Replies
This is the nobility for hybrids source.
Use the 5018+ arco released.
Is converted from the 5165source.
Go to Packets.cs and put:
public class Packets
{
public static COPacket Donators(GameClient C)
{
[RELEASE] COEMU 5095 SOURCE, WITH FLOWERS, NOBILITY, MANY MORE READ!
11/11/2009 - CO2 PServer Guides & Releases - 58 Replies
#closed.... -.-
[REQUEST] Nobility For Coemu Source
08/08/2009 - CO2 Programming - 0 Replies
I need to add Nobility to my Coemu Source, if someone could please help me...
All times are GMT +2. The time now is 16:59 .