custom xp rate base on time range

i has write a path,that let you can set rate for special time range。

i tried 2 ways to fetch time range and xp rate info from db.

1.use prestatement , it is failed, when my character killed a createture my server was stopping response

PrepareStatement(LOGIN_SEL_EXP_EVENT, “SELECT xp_rate FROM exp_event WHERE NOW() >= start_time AND NOW() <= end_time AND is_active = 1 ORDER BY id DESC LIMIT 1”, CONNECTION_SYNCH);PreparedStatement *pr = LoginDatabase.GetPreparedStatement(LOGIN_SEL_EXP_EVENT);
2.use direct execute sql, it is work. but i very worry about performance

QueryResult result = LoginDatabase.Query(“SELECT xp_rate FROM exp_event WHERE NOW() >= start_time AND NOW() <= end_time AND is_active = 1 ORDER BY id DESC LIMIT 1”);

please help me understand.

[ATTACH]1304._xfImport[/ATTACH]

  • MAX_LOGINDATABASE_STATEMENTS,
  • LOGIN_SEL_EXP_EVENT // 经验活动

MAX_LOGINDATABASE_STATEMENTS MUST be the last statement. Place your own before that.

.Query() shouldn’t hurt too much performance-wise, however with that change it should work.

​thanks, i will try it later at home.

I’d load that exp event table to memory instead of querying the DB everytime a player gets xp from any source. You can also do single update on the xp rates during those exp events time (Or just check every minute) hurts way less.

​i don’t konw that how to implement a timer check it every minute.

give me some snippet (example code). ​

In World.cpp

World::Update

something like:

[CODE]if (m_gameTime > m_NextXpRatesCheck)

{
m_NextXpRatesCheck = time_t(m_NextXpRatesCheck + 60);

    // Do DB query and update xp rate values

}[/CODE]

thank you very much ! agin.