Jump to content
  • 0

Call database .db in server?? [DEV]


nvh

Question

13 answers to this question

Recommended Posts

  • 0

You dont need to use raw SQL, let EntityFramework do that for you.

An example for what are you trying to do is 

OnlinePlayers.OrderByDescending(p => p.Value.Exp).ToList();

So you got an ordered list of online players by Exp amount.

Put that in communication between packets so clients can see it.

Link to comment
Share on other sites

  • 0
  On 9/28/2021 at 1:14 PM, boasfesta said:

You dont need to use raw SQL, let EntityFramework do that for you.

An example for what are you trying to do is 

OnlinePlayers.OrderByDescending(p => p.Value.Exp).ToList();

So you got an ordered list of online players by Exp amount.

Put that in communication between packets so clients can see it.

Expand  

Oh thank u. where do i write that code?

how to show top 20 player (Name & level, no need online) ?

Link to comment
Share on other sites

  • 0
  On 9/28/2021 at 11:03 PM, nvh said:

Oh thank u. where do i write that code?

how to show top 20 player (Name & level, no need online) ?

Expand  

 

You'd likely want to add your own new compiled query in Player.Database.cs on the server, then write up a UI or something on the client that will display this and request it from the server with a packet when the user opens this menu.

 

Personally I would cache this query result, because once you get a couple thousand accounts it could start taking longer and longer as your game keeps getting players to come and try it.

Link to comment
Share on other sites

  • 0
  On 9/29/2021 at 4:58 AM, Cheshire said:

 

You'd likely want to add your own new compiled query in Player.Database.cs on the server, then write up a UI or something on the client that will display this and request it from the server with a packet when the user opens this menu.

 

Personally I would cache this query result, because once you get a couple thousand accounts it could start taking longer and longer as your game keeps getting players to come and try it.

Expand  

What is the syntax to be able to write it?
Can I save it to a file top.json and update it every 12h to keep the server from slowing down?

Dialog from client can call command like \onlinelist

Link to comment
Share on other sites

  • 0
  On 9/29/2021 at 5:28 AM, nvh said:

What is the syntax to be able to write it?
Can I save it to a file top.json and update it every 12h to keep the server from slowing down?

Dialog from client can call command like \onlinelist

Expand  

 

Chesire is right. Caching its best way to keep performance. Try to declare an public static List and update it every 60m for example.

But if you're using MySQL and considering that people wont check the toplist everytime. You dont need to worry about caching up at all. Even a huge table wont be affected that much.

So for a command /top, just code something like this:

 

if (command = "/top") {
var topList = OnlinePlayers.OrderByDescending(x => x.Value.Exp).ToList();
var topListString = string.Empty;
foreach (var player in topList){
// concat topListString here
}

//SendChatMsg blablabla topliststring 
}

 

Link to comment
Share on other sites

  • 0
  On 9/29/2021 at 4:26 PM, boasfesta said:

 

Chesire is right. Caching its best way to keep performance. Try to declare an public static List and update it every 60m for example.

But if you're using MySQL and considering that people wont check the toplist everytime. You dont need to worry about caching up at all. Even a huge table wont be affected that much.

So for a command /top, just code something like this:

 

if (command = "/top") {
var topList = OnlinePlayers.OrderByDescending(x => x.Value.Exp).ToList();
var topListString = string.Empty;
foreach (var player in topList){
// concat topListString here
}

//SendChatMsg blablabla topliststring 
}

 

Expand  

which file .cs for this code? can show player name of this.valueEXP ?

Link to comment
Share on other sites

  • 0
  On 9/30/2021 at 12:40 AM, nvh said:

which file .cs for this code? can show player name of this.valueEXP ?

Expand  

Function public void HandlePacket(Client client, ChatMsgPacket packet) in PacketHandler.cs at Intersect.Server its a good place.

And yup, you can show the player name since the list only order players by exp, but his whole data is returned.

Link to comment
Share on other sites

  • 0
  On 9/30/2021 at 3:18 AM, boasfesta said:

Hàm public void HandlePacket (Client client, gói ChatMsgPacket) trong PacketHandler.cs tại Intersect.Server là một nơi tốt.

Và đúng vậy, bạn có thể hiển thị tên người chơi vì danh sách chỉ sắp xếp người chơi theo điểm kinh nghiệm, nhưng toàn bộ dữ liệu của anh ta sẽ được trả về.

Expand  

can I using this ?37108bb96738a4031aebdd43f4025008.png

Link to comment
Share on other sites

  • 0

You can. But that method seems to be called at every event command, so even if you're not asking for a toplist, the system will check the database for a ordered list. Consider making a cache if that becomes laggy.

 

Just do that string.Join in a topList.Select(x => x.Name).toList(), it should world.

Link to comment
Share on other sites

  • 0
  On 10/1/2021 at 1:18 PM, boasfesta said:

You can. But that method seems to be called at every event command, so even if you're not asking for a toplist, the system will check the database for a ordered list. Consider making a cache if that becomes laggy.

 

Just do that string.Join in a topList.Select(x => x.Name).toList(), it should world.

Expand  

is there any way to fix it? 
{@“\command”, set method in here}??

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...