VIP Subscription System

09/16/2013 21:42 shadowman123#1
sm1 asked me to do that system for him so i finished it and Decided to Release it For all members in case sm1 wanted to add it too ... anyways its pretty easy to be added

This Guide Is For Beginers ..Im Sure All Expert Members dont need Explaination for these methods

Lets Start By Database
PHP Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 
Conquer_Online_Server.Database
{
  public class 
VipVariables
  
{
    public 
string PlayerNameSuscribtionDate;
    public 
byte Days 0VIPLevel 0;
  }

  class 
VipTable
  
{
    public static 
Dictionary<stringVipVariablesVipList = new Dictionary<stringVipVariables>();
    public static 
void LoadAllVips()
    {
      
VipList.Clear();
      
MySqlCommand Cmd = new MySqlCommand(MySqlCommandType.SELECT);
      
Cmd.Select("VIP");
      
MySqlReader Reader = new MySqlReader(Cmd);
      while (
Reader.Read())
      {
        
VipVariables vip = new VipVariables();
        
vip.PlayerName Reader.ReadString("PlayerName");
        
vip.SuscribtionDate Reader.ReadString("SuscribtionDate");
        
vip.Days Reader.ReadByte("Days");
        
vip.VIPLevel Reader.ReadByte("VIPLevel");
        
VipList.Add(vip.PlayerNamevip);
       }
       
Reader.Close();
       
Reader.Dispose();
       
Program.WriteLine("All Vip Players Are Loaded.");
    }

    public static 
void SavePlayer(Client.GameState clientbyte VIPLevelbyte Days)
    {
      new 
MySqlCommand(MySqlCommandType.INSERT).Insert("VIP").Insert("PlayerName"client.Entity.Name).Insert("SuscribtionDate"DateTime.Now.ToShortTimeString()).Insert("VIPLevel"VIPLevel).Insert("Days"Days).Execute();
      
LoadAllVips();
    }

    public static 
void Delete(string PlayerName)
    {
      new 
MySqlCommand(MySqlCommandType.DELETE).Delete("VIP""PlayerName",PlayerName).Execute();
      
Program.WriteLine(PlayerName "'s Vip Suscribtion is Expired");
    }
  }

The Add that Line In GameState.cs
PHP Code:
public Database.VipVariables VIPInformation = new Database.VipVariables(); 
Add this Line in program.cs ... that line Loads All VIP values inside VIP Table when server starts
PHP Code:
Database.VipTable.LoadAllVips(); 
This Void Should Be Called When Restarting The Server in order to Decrease the Suscribtion Days by 1
PHP Code:
static void VIPDaysReduction()
{
  foreach (var 
VIPMember in Database.VipTable.VipList.Values)
  {
    
byte Days VIPMember.Days;
    new 
MySqlCommand(MySqlCommandType.UPDATE).Update("VIP").Set("Days"Days Days-- : 0).Where("PlayerName"VIPMember.PlayerName).Execute();
   }


Add this In EntityTable.cs To Check If The Player is Suscribed IN VIP .. if Days == 0 This Means that his Suscribtion is Expired So Deleting This Player From VIP Database
PHP Code:
if (Database.VipTable.VipList.ContainsKey(client.Entity.Name))
{
  
client.VIPInformation Database.VipTable.VipList[client.Entity.Name];
  if (
client.VIPInformation.Days == 0)
  {
    
client.SendMessage("Your VIP Suscribtion Has Expired"Message.TopLeft);
    
Database.VipTable.Delete(client.Entity.Name);
  }

NOTE : SendMessage is My Method of Sending Messages so Dont use Mine Or you are going to have Errors so Replace it With Yours


Add it In LoginMessages Void Inside PacketHandler.cs To Send Vip Packet to Player if he is VIP
PHP Code:
client.Entity.VIPLevel client.VIPInformation.VIPLevel;
if (
client.Entity.VIPLevel 0)
{
  
client.Send(new VIPAdvanced(true) { UID client.Entity.UID });

NOTE : You Should Handle The way of Adding Players In Database Yourself Either using Commands , Website or w.e ur way is ..thats y i didnt do the SavePlayer Method Calling

Then you are done with adding the System
Hope it helps you guyz

VIP Table in Attachment .. just Upload it to your Server Database

BTW I Dont Mind Sharing My Codes As long As you are giving me The Credits

Regards
Shadowman123
09/16/2013 22:43 _Emme_#2
Just to let you know, save the entity ID instead of the name. Not only is it smaller in the database, but if the player changes name for example, other things linked to the character won't follow.
09/16/2013 22:51 shadowman123#3
Quote:
Originally Posted by 'Emil View Post
Just to let you know, save the entity ID instead of the name. Not only is it smaller in the database, but if the player changes name for example, other things linked to the character won't follow.
well u r Right ... but if sm1 changed his name then the system should Change his name inside VIP Table too .. so its not a big Deal .. beside that Personally i'd like to know who Exactly is VIP by checking in Table i know that rather than getting Players UID then going to Entities but u gave good Note ...

NOTE :-
I Accept Any Constructive Critisize So Feel Free to Do that
09/16/2013 23:25 shadowman123#4
Quote:
Originally Posted by Y u k i View Post
Why wouldnt you query if the player is VIP on Login? You cache the table once on startup.. why? If your server is shitty enough to require a restart every 24h nobody should waste money on buying VIP.
About Restarting Server i dont see any problem in Restarting Server .. btw Restarting a Server Doesnt mean that its Shitty Or bad .. Most of Online Games do Daily Restart Servers ... if i didnt Restart my server it would consume Alot of memory .. for example i left the Application On For one week .. do u imagine how much memory will be consumed ? ..especially that each player consumes about 30 MB when Login

About Y i sent VIP Checker when player Logins .. when player login if he is VIP i should Send him VIP Packet so best Time to check if player is VIP or not is when he Logins

i didnt understand this question You cache the table once on startup.. why? could u tell me what u mean

Thx Alot for Commenting on My Cods i like Discussion
09/16/2013 23:59 Y u k i#5
Quote:
Originally Posted by shadowman123 View Post
About Restarting Server i dont see any problem in Restarting Server .. btw Restarting a Server Doesnt mean that its Shitty Or bad .. Most of Online Games do Daily Restart Servers ... if i didnt Restart my server it would consume Alot of memory .. for example i left the Application On For one week .. do u imagine how much memory will be consumed ? ..especially that each player consumes about 30 MB when Login

About Y i sent VIP Checker when player Logins .. when player login if he is VIP i should Send him VIP Packet so best Time to check if player is VIP or not is when he Logins

i didnt understand this question You cache the table once on startup.. why? could u tell me what u mean

Thx Alot for Commenting on My Cods i like Discussion
Well, About that Memory... Why would your Server not free up memory after a Client disconnects? and 30 MB per Client? There must be something going badly wrong.

I mean like doing
PHP Code:
MySqlCommand Cmd = new MySqlCommand(MySqlCommandType.SELECT);
      
Cmd.Select("VIP""PLAYERNAME OR UID"); 
everythime a Player connects, but only for that one Player. Your MySQL system looks weird to me tbh but what do i know.

IŽd first asure that the server runs decently (not taking up 30mb per client - thats ridiculos) then implement more "features"

MySQL shouldnt have a problem with a few hundret to thousand queries. AND! You would save some KB on memory, because there is no need to store that information once the check completed.
09/17/2013 00:32 abdoumatrix#6
Nice Job u can do better i think u was bored and busy

this is much better than the Day--

09/17/2013 00:53 shadowman123#7
Quote:
Originally Posted by Y u k i View Post
Well, About that Memory... Why would your Server not free up memory after a Client disconnects? and 30 MB per Client? There must be something going badly wrong.

I mean like doing
PHP Code:
MySqlCommand Cmd = new MySqlCommand(MySqlCommandType.SELECT);
      
Cmd.Select("VIP""PLAYERNAME OR UID"); 
everythime a Player connects, but only for that one Player. Your MySQL system looks weird to me tbh but what do i know.

IŽd first asure that the server runs decently (not taking up 30mb per client - thats ridiculos) then implement more "features"

MySQL shouldnt have a problem with a few hundret to thousand queries. AND! You would save some KB on memory, because there is no need to store that information once the check completed.
i have to tell you 3 Things :-
first is thanq alot of clarifying things to me .. i didnt know that MYSQL having problem with Queries Bet Hundreds and Thousands ...

Second you are right i should load each player separately ...would be easier

Third all the recent released sources contains Two Classes which do MemoryCompress and CPU Reduction ..i already added them and player login just take about 1 MB by using this system but i saw sm1 saying that its very very bad to use smthing like that as it affects on server Efficiency badly ...so idk what to do ... and by the way i guess Inproper use of programming Types is the main reason of taking that much Size of Memory ( 30 MB or so ) ..so by replacing types with the Best Choice i can go Lower than that .. Right ?
09/17/2013 02:27 Smallxmac#8
I'm not sure how good of a way I did it, but when ever someone gets a vip subscription it adds 31 days to the current date and then save the new date in the database it then also goes on and puts a 1 in the VIP column. When the client logs it will check if VIP is = to 1 if so it will check the date to make sure it is still valid, if not it sets the date to nothing and then makes VIP 0. By doing it this way you do not have to load what you do not need.
09/17/2013 02:47 vtnc2#9
Where do we add the first step that you say "let's start by database"...?
09/17/2013 03:07 Smallxmac#10
I would only guess the database folder in the source make a new Code file and put that in there, I would not suggest just copying all this crap down. Learn what it is doing and understand it.
09/17/2013 04:48 Super Aids#11
After executing a mysql command does it close the connection? Seems like you're keeping the connection open.
09/17/2013 05:28 Smallxmac#12
I'm not sure if I am is right or wrong but I have seen so many examples that never seem to close in that class. I think the MysqlCommand closes it after it is done so you do not have to keep calling the connection to be closed. But hey, I may be wrong lol I have not even looked at it. That just seems like the logical thing to do.
09/17/2013 05:59 shadowman123#13
Quote:
Originally Posted by Super Aids View Post
After executing a mysql command does it close the connection? Seems like you're keeping the connection open.
im using Kill Connection method that FANG Released long while ago .. running in 1 sec Run Time Thread .. i know its now what should be Done .. but ill Fix that Later
09/17/2013 06:11 Super Aids#14
Why are people using such horrible wrapper that requires that? You should ALWAYS close a connection as soon as you have executed a query.
09/17/2013 06:54 shadowman123#15
ill Fix that ASAP .. Thx Alot for your comments guyz .. it helped me Alot