summaryrefslogtreecommitdiff
path: root/src/char/char.c
diff options
context:
space:
mode:
authorskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-08-15 22:08:30 +0000
committerskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-08-15 22:08:30 +0000
commitefae7aa61b3b4d7fbb2782e8f00e27a6adc325c1 (patch)
treea56b8db8327b7fe6f71953469efd34952da10f0a /src/char/char.c
parent0135f76b2a674a4824c33ac9d5e7ca65c945c7c4 (diff)
downloadhercules-efae7aa61b3b4d7fbb2782e8f00e27a6adc325c1.tar.gz
hercules-efae7aa61b3b4d7fbb2782e8f00e27a6adc325c1.tar.bz2
hercules-efae7aa61b3b4d7fbb2782e8f00e27a6adc325c1.tar.xz
hercules-efae7aa61b3b4d7fbb2782e8f00e27a6adc325c1.zip
- Merged and completed Latio's work on server-side hot-key saving (http://www.eathena.ws/board/index.php?s=&showtopic=159388&view=findpost&p=884453)
- Now hotkeys are stored server-side (table hotkey in SQL servers, file save/hotkeys.txt for TXT servers). You can disable this behaviour by commenting out the 'HOTKEY_SAVING' define in mmo.h - Fixed a few compilation warnings/errors. - Apply upgrade_svn11018.sql to create the hotkey table. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11019 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/char/char.c')
-rw-r--r--src/char/char.c82
1 files changed, 80 insertions, 2 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 7d39e6d92..2ae559f20 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -46,6 +46,7 @@
char char_txt[1024] = "save/athena.txt";
char friends_txt[1024] = "save/friends.txt";
+char hotkeys_txt[1024] = "save/hotkeys.txt";
char char_log_filename[1024] = "log/char.log";
int save_log = 1; // show loading/saving messages
@@ -445,6 +446,22 @@ int mmo_friends_list_data_str(char *str, struct mmo_charstatus *p)
return 0;
}
+/*---------------------------------------------------
+ Make a data line for hotkeys list
+ --------------------------------------------------*/
+int mmo_hotkeys_tostr(char *str, struct mmo_charstatus *p)
+{
+ int i;
+ char *str_p = str;
+ str_p += sprintf(str_p, "%d", p->char_id);
+#ifdef HOTKEY_SAVING
+ for (i=0;i<HOTKEY_SAVING;i++)
+ str_p += sprintf(str_p, ",%d,%d,%d", p->hotkeys[i].type, p->hotkeys[i].id, p->hotkeys[i].lv);
+#endif
+ str_p += '\0';
+
+ return 0;
+}
//-------------------------------------------------
// Function to create the character line (for save)
//-------------------------------------------------
@@ -891,6 +908,53 @@ int parse_friend_txt(struct mmo_charstatus *p)
return count;
}
+//---------------------------------
+// Function to read hotkey list
+//---------------------------------
+int parse_hotkey_txt(struct mmo_charstatus *p)
+{
+#ifdef HOTKEY_SAVING
+ char line[1024];
+ int pos = 0, count = 0, next;
+ int i,len;
+ int type, id, lv;
+ FILE *fp;
+
+ // Open the file and look for the ID
+ fp = fopen(hotkeys_txt, "r");
+ if(fp == NULL)
+ return -1;
+
+ while(fgets(line, sizeof(line), fp))
+ {
+ if(line[0] == '/' && line[1] == '/')
+ continue;
+ if (sscanf(line, "%d%n",&i, &pos) < 1 || i != p->char_id)
+ continue; //Not this line...
+ //Read hotkeys
+ len = strlen(line);
+ next = pos;
+ for (count = 0; next < len && count < HOTKEY_SAVING; count++)
+ {
+ if (sscanf(line+next, ",%d,%d,%d%n",&type,&id,&lv, &pos) < 3)
+ //Invalid entry?
+ break;
+ p->hotkeys[count].type = type;
+ p->hotkeys[count].id = id;
+ p->hotkeys[count].lv = lv;
+ next+=pos;
+ }
+ break; //Found hotkeys.
+ }
+ fclose(fp);
+ return count;
+#else
+ return 0;
+#endif
+}
+
+
+
#ifndef TXT_SQL_CONVERT
//---------------------------------
// Function to read characters file
@@ -944,7 +1008,9 @@ int mmo_char_init(void)
// Initialize friends list
parse_friend_txt(&char_dat[char_num].status); // Grab friends for the character
-
+ // Initialize hotkey list
+ parse_hotkey_txt(&char_dat[char_num].status); // Grab hotkeys for the character
+
if (ret > 0) { // negative value or zero for errors
if (char_dat[char_num].status.char_id >= char_id_count)
char_id_count = char_dat[char_num].status.char_id + 1;
@@ -1049,7 +1115,17 @@ void mmo_char_sync(void)
lock_fclose(f_fp, friends_txt, &lock);
- //aFree(id);
+#ifdef HOTKEY_SAVING
+ // Hotkey List data save (Skotlex)
+ f_fp = lock_fopen(hotkeys_txt, &lock);
+ for(i = 0; i < char_num; i++) {
+ mmo_hotkeys_tostr(f_line, &char_dat[id[i]].status);
+ fprintf(f_fp, "%s" RETCODE, f_line);
+ }
+
+ lock_fclose(f_fp, hotkeys_txt, &lock);
+#endif
+
DELETE_BUFFER(id);
return;
@@ -4059,6 +4135,8 @@ int char_config_read(const char *cfgName)
strcpy(char_txt, w2);
} else if (strcmpi(w1, "friends_txt") == 0) { //By davidsiaw
strcpy(friends_txt, w2);
+ } else if (strcmpi(w1, "hotkeys_txt") == 0) { //By davidsiaw
+ strcpy(hotkeys_txt, w2);
#ifndef TXT_SQL_CONVERT
} else if (strcmpi(w1, "max_connect_user") == 0) {
max_connect_user = atoi(w2);