Skip to content

Commit

Permalink
Merge pull request #9 from shnok/dev
Browse files Browse the repository at this point in the history
autoselect last logged in character
  • Loading branch information
shnok authored Jul 3, 2024
2 parents 6008eda + eba7d52 commit 5b505c4
Show file tree
Hide file tree
Showing 7 changed files with 566 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gameserver/conf/hexid.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#the hexID to auth into login
#Wed Jul 03 01:44:57 SGT 2024
#Wed Jul 03 11:17:46 SGT 2024
HexID=81a8ba90db0e77d303397388e25ecefa
ServerID=1
Binary file modified gameserver/db/l2-unity.mv.db
Binary file not shown.
538 changes: 538 additions & 0 deletions gameserver/db/l2-unity.trace.db

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion gameserver/db/scripts/create-db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ CREATE TABLE `character`(
pk_kills INT DEFAULT 0,
clan_id INT,
max_weight INT DEFAULT 0,
online_time BIGINT DEFAULT 0,
last_login BIGINT DEFAULT 0,
delete_time BIGINT,
create_date BIGINT DEFAULT 0 NOT NULL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public class DBCharacter {
@Column(name = "online")
private boolean online;

@Column(name = "online_time")
private Long onlineTime;

@Column(name = "char_slot")
private Byte charSlot;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.extern.log4j.Log4j2;
import org.hibernate.Session;

import javax.persistence.Query;
import java.util.List;
import java.util.Random;

Expand Down Expand Up @@ -85,14 +86,34 @@ public int saveCharacter(DBCharacter character) {

@Override
public void setCharacterOnlineStatus(int id, boolean isOnline) {
DBCharacter character = getCharacterById(id);
if(character != null) {
character.setOnline(isOnline);
try (Session session = DbFactory.getSessionFactory().openSession()) {
session.beginTransaction();

Query query;
if(isOnline) {
character.setOnlineTime(System.currentTimeMillis());
String hql = "UPDATE DBCharacter SET online = :isOnline, lastLogin = :lastLogin WHERE id = :id";
query = session.createQuery(hql);
query.setParameter("isOnline", true);
query.setParameter("lastLogin", System.currentTimeMillis());
query.setParameter("id", id);
} else {
String hql = "UPDATE DBCharacter SET online = :isOnline WHERE id = :id";
query = session.createQuery(hql);
query.setParameter("isOnline", false);
query.setParameter("id", id);
}

saveOrUpdateCharacter(character);
int rowsUpdated = query.executeUpdate();

session.getTransaction().commit();

if (rowsUpdated > 0) {
log.debug("Character ID: " + id + " updated successfully.");
} else {
log.warn("No character found with ID: " + id);
}
} catch (Exception e) {
log.error("SQL ERROR: {}", e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public void setOnlineStatus(boolean isOnline, boolean updateInDb) {
public void destroy() {
super.destroy();

setOnlineStatus(false, true);
WorldManagerService.getInstance().removePlayer(this);
}
}

0 comments on commit 5b505c4

Please sign in to comment.