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
10 hours ago, 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.

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
5 hours ago, nvh said:

Oh thank u. where do i write that code?

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

 

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
27 minutes ago, 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.

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
10 hours ago, 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

 

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
8 hours ago, 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 
}

 

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

Link to comment
Share on other sites

  • 0
2 hours ago, nvh said:

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

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
21 hours ago, 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ề.

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
1 hour ago, 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.

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

Link to comment
Share on other sites

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

{@“\command”, string.Join(Environment.NewLine, topList.Select(x => x.Name).ToList())} should work

thank u. I have toplv online (auto)

I will query with .db to create a top lv offline (manually)

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...