SalemEGY

RankList_For_DOTNet_Pages

Jul 4th, 2024
676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.56 KB | Software | 0 0
  1. /**
  2. step 1:
  3. open GameServer Project Add New Class name it : Rankings.cs
  4. then add this code to your class
  5. **/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using COServer.Client;
  11. using COServer;
  12. using COServer.Database;
  13. using Extensions;
  14.  
  15. namespace COServer
  16. {
  17.     class Rankings
  18.     {
  19.         public static Dictionary<uint, Entities> Ranklist = new Dictionary<uint, Entities>();
  20.         public class Entities
  21.         {
  22.  
  23.             public uint UID;
  24.             public string Name = "";
  25.             public ushort Level;
  26.             public long Money;
  27.             public ulong Donation;
  28.             public uint ConquerPoints;
  29.             public byte VipLevel;
  30.             public byte Class;
  31.             public ushort Face;
  32.            
  33.         }
  34.         public static void Update(GameClient client)
  35.         {
  36.        
  37.            
  38.             if (!Ranklist.ContainsKey(client.Player.UID))
  39.             {
  40.                 Entities players = new Entities();
  41.                 players.UID = client.Player.UID;
  42.                 players.Name = client.Player.Name;
  43.                 Ranklist.Add(players.UID, players);
  44.  
  45.              
  46.             }
  47.             else
  48.             {
  49.                 Refresh(client);
  50.             }
  51.            
  52.         }
  53.         public static void check(GameClient client)
  54.         {
  55.             using (var command = new MySqlCommand(MySqlCommandType.SELECT))
  56.             {
  57.                 command.Select("Rankings").Where("UID", client.Player.UID);
  58.                 using ( var reader = new MySqlReader(command, true))
  59.                 {
  60.                     if (!reader.Read())
  61.                     {
  62.  
  63.                         using (var cmd = new MySqlCommand(MySqlCommandType.INSERT))
  64.                         {
  65.                             cmd.Insert("Rankings")
  66.                             .Insert("UID", client.Player.UID)
  67.                             .Insert("Name", client.Player.Name)
  68.                             .Execute();
  69.                         }
  70.                     }
  71.                 }
  72.             }
  73.         }
  74.         public static void Refresh(GameClient client)
  75.         {
  76.             if (Ranklist.ContainsKey(client.Player.UID))
  77.             {
  78.                 var Player = Ranklist[client.Player.UID];
  79.                 Player.Level = client.Player.Level;
  80.                 Player.Money = client.Player.Money;
  81.                 Player.Donation = client.Player.Nobility.Donation;
  82.                 Player.ConquerPoints = client.Player.ConquerPoints;
  83.                 Player.VipLevel = client.Player.VipLevel;
  84.                 Player.Class = client.Player.Class;
  85.                 Player.Face = client.Player.Face;
  86.                 using (var cmd = new MySqlCommand(MySqlCommandType.UPDATE))
  87.                 {
  88.                     cmd.Update("Rankings")
  89.                    .Set("Level", Player.Level)
  90.                    .Set("Gold", Player.Money)
  91.                    .Set("Donation", Player.Donation)
  92.                    .Set("cps", Player.ConquerPoints)
  93.                    .Set("VIPLevel", Player.VipLevel)
  94.                    .Set("Class", Player.Class)
  95.                    .Set("Face", Player.Face)
  96.                    .Where("UID", Player.UID)
  97.                    .Execute();
  98.  
  99.                 }
  100.             }
  101.            
  102.  
  103.         }
  104.  
  105.         public static void Load()
  106.         {
  107.             using (var command = new MySqlCommand(MySqlCommandType.SELECT))
  108.             {
  109.                 command.Select("Rankings").Where("UID", 0, true);
  110.                 using (var reader = new MySqlReader(command))
  111.                 {
  112.                     while (reader.Read())
  113.                     {
  114.                         Entities players = new Entities();
  115.                         players.UID = reader.ReadUInt32("UID");
  116.                         players.Name = reader.ReadString("Name");
  117.                         players.Level = reader.ReadByte("Level");
  118.                         players.Money = reader.ReadInt64("Gold");
  119.                         players.ConquerPoints = reader.ReadUInt32("cps");
  120.                         players.VipLevel = reader.ReadByte("VIPLevel");
  121.                         players.Class = reader.ReadByte("Class");
  122.                         if (!Ranklist.ContainsKey(players.UID))
  123.                         {
  124.                             Ranklist.Add(players.UID,players);
  125.  
  126.                         }
  127.  
  128.                     }
  129.                 }
  130.             }
  131.          
  132.         }
  133.         public static void Save()
  134.         {
  135.             foreach (var player in Rankings.Ranklist.Values)
  136.             {
  137.                 using (var cmd = new MySqlCommand(MySqlCommandType.UPDATE))
  138.                 {
  139.                     cmd.Update("Rankings")
  140.                    .Set("Level", player.Level)
  141.                    .Set("Gold", player.Money)
  142.                    .Set("Donation", player.Donation)
  143.                    .Set("cps", player.ConquerPoints)
  144.                    .Set("VIPLevel", player.VipLevel)
  145.                    .Set("Class", player.Class)
  146.                    .Where("UID", player.UID)
  147.                    .Execute();
  148.  
  149.                 }
  150.             }
  151.            
  152.         }
  153.         }
  154.     }
  155. }
  156. /////////////////////////////////////////////////////////
  157. ///////////////////////////////////////////
  158. ///////////////////////////////
  159. ///////////////////
  160. /**
  161. step 2:
  162. goto class Server.cs
  163. search for : IniFile.Write<uint>("Config", "Day", ResetServerDay);
  164. add this code after it
  165. **/
  166.  
  167. Save(new Action(Rankings.Save));
  168.  
  169. ////////////////////////////////////////////////////////
  170. /**
  171. step 3:
  172. in the same class srech for :
  173. Shops.ShopFile.Load();
  174. and add this code after
  175. **/
  176.  
  177. Rankings.Load();
  178.  
  179. //////////////////////////////////////////////////////
  180. /**
  181. step 4:
  182. goto MsgLoginClient.cs
  183. search for : Playeracc.WriteName(client);
  184. you will found 2 result of this line
  185. after each line of them add this code:
  186. **/
  187.  
  188. Rankings.check(client);
  189.  
  190. ////////////////////////////////////////////////////////
  191. /**
  192. step 5:
  193. goto Program.cs
  194. search for this void :
  195. public static void SaveDBPayers(Extensions.Time32 clock)
  196. then inside this void you will found this if condaition :
  197. ##########################################################################################
  198. if ((user.ClientFlag & Client.ServerFlag.LoginFull) == Client.ServerFlag.LoginFull)`     #
  199. {                                                                                        #
  200.     user.ClientFlag |= Client.ServerFlag.QueuesSave;                                     #
  201.     Database.ServerDatabase.LoginQueue.TryEnqueue(user);                                 #
  202.                                                                                          #
  203. }                                                                                        #
  204. ##########################################################################################
  205. after this if condaition brackets we will add this code :
  206. ########################
  207. #Rankings.Update(user);#
  208. ########################
  209. to be like this code
  210. ##########################################################################################
  211. if ((user.ClientFlag & Client.ServerFlag.LoginFull) == Client.ServerFlag.LoginFull)`     #
  212. {                                                                                        #
  213.     user.ClientFlag |= Client.ServerFlag.QueuesSave;                                     #
  214.     Database.ServerDatabase.LoginQueue.TryEnqueue(user);                                 #
  215.                                                                                          #
  216. }                                                                                        #
  217. Rankings.Update(user);                                                                   #
  218. ##########################################################################################
  219. **/
  220. /////////////////////////////////////////////
  221. /**
  222. step 6:
  223. goto navicat then right click on ur dbname then -> Console
  224. and copy this code to ur db console
  225. **/
  226. -- ----------------------------
  227. -- Table structure for rankings
  228. -- ----------------------------
  229. DROP TABLE IF EXISTS `rankings`;
  230. CREATE TABLE `rankings`  (
  231.   `UID` bigint(16) UNSIGNED NULL DEFAULT NULL,
  232.   `Name` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  233.   `Level` bigint(16) NULL DEFAULT NULL,
  234.   `Gold` bigint(18) UNSIGNED NULL DEFAULT NULL,
  235.   `Donation` bigint(25) UNSIGNED NULL DEFAULT NULL,
  236.   `cps` bigint(18) UNSIGNED NULL DEFAULT 0,
  237.   `VIPLevel` tinyint(5) UNSIGNED NOT NULL,
  238.   `Class` bigint(16) NULL DEFAULT NULL,
  239.   `Face` int(5) UNSIGNED NULL DEFAULT NULL
  240. ) ENGINE = MyISAM CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
  241.  
  242. /////////////////////////////////////////////////////////////////
  243.  
  244. /**
  245.  
  246. ##################################################################################################
  247. this code for Conquer Developers Facebook Group: https://www.facebook.com/groups/cocoders/
  248. By : Salem Ahmed
  249. Use It To Read And write ranks in mysql db and pass data to Web Page
  250.  
  251. ##################################################################################################
  252.  
  253. **/
  254.  
Advertisement
Add Comment
Please, Sign In to add comment