diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2012-12-13 16:25:50 -0800 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2012-12-14 16:18:22 -0800 |
commit | 069f39e8a1ebee3e4a4ce8302d0099842876782b (patch) | |
tree | 57d8de5f57d65878f8ef560e2884b9dee08e9323 /src/char/int_storage.cpp | |
parent | f9563edf69f083287630f4b17db70d97524196d6 (diff) | |
download | tmwa-069f39e8a1ebee3e4a4ce8302d0099842876782b.tar.gz tmwa-069f39e8a1ebee3e4a4ce8302d0099842876782b.tar.bz2 tmwa-069f39e8a1ebee3e4a4ce8302d0099842876782b.tar.xz tmwa-069f39e8a1ebee3e4a4ce8302d0099842876782b.zip |
Some formatting fixes before I go insane
Also delete the French translation from ladmin.
Diffstat (limited to 'src/char/int_storage.cpp')
-rw-r--r-- | src/char/int_storage.cpp | 149 |
1 files changed, 74 insertions, 75 deletions
diff --git a/src/char/int_storage.cpp b/src/char/int_storage.cpp index 8aa615f..a968c2a 100644 --- a/src/char/int_storage.cpp +++ b/src/char/int_storage.cpp @@ -19,16 +19,16 @@ static struct dbt *storage_db; // 倉庫データを文字列に変換 static -int storage_tostr (char *str, struct storage *p) +int storage_tostr(char *str, struct storage *p) { - int i, f = 0; + int i, f = 0; char *str_p = str; - str_p += sprintf (str_p, "%d,%d\t", p->account_id, p->storage_amount); + str_p += sprintf(str_p, "%d,%d\t", p->account_id, p->storage_amount); for (i = 0; i < MAX_STORAGE; i++) if ((p->storage_[i].nameid) && (p->storage_[i].amount)) { - str_p += sprintf (str_p, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ", + str_p += sprintf(str_p, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ", p->storage_[i].id, p->storage_[i].nameid, p->storage_[i].amount, p->storage_[i].equip, p->storage_[i].identify, p->storage_[i].refine, @@ -48,12 +48,12 @@ int storage_tostr (char *str, struct storage *p) // 文字列を倉庫データに変換 static -int storage_fromstr (char *str, struct storage *p) +int storage_fromstr(char *str, struct storage *p) { - int tmp_int[256]; - int set, next, len, i; + int tmp_int[256]; + int set, next, len, i; - set = sscanf (str, "%d,%d%n", &tmp_int[0], &tmp_int[1], &next); + set = sscanf(str, "%d,%d%n", &tmp_int[0], &tmp_int[1], &next); p->storage_amount = tmp_int[1]; if (set != 2) @@ -63,7 +63,7 @@ int storage_fromstr (char *str, struct storage *p) next++; for (i = 0; str[next] && str[next] != '\t' && i < MAX_STORAGE; i++) { - if (sscanf (str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n", + if (sscanf(str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n", &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6], &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], @@ -85,7 +85,7 @@ int storage_fromstr (char *str, struct storage *p) next++; } - else if (sscanf (str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n", + else if (sscanf(str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n", &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6], &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], @@ -111,122 +111,121 @@ int storage_fromstr (char *str, struct storage *p) return 1; } if (i >= MAX_STORAGE && str[next] && str[next] != '\t') - printf - ("storage_fromstr: Found a storage line with more items than MAX_STORAGE (%d), remaining items have been discarded!\n", + printf("storage_fromstr: Found a storage line with more items than MAX_STORAGE (%d), remaining items have been discarded!\n", MAX_STORAGE); return 0; } // アカウントから倉庫データインデックスを得る(新規倉庫追加可能) -struct storage *account2storage (int account_id) +struct storage *account2storage(int account_id) { struct storage *s; - s = (struct storage *) numdb_search (storage_db, account_id); + s = (struct storage *) numdb_search(storage_db, account_id); if (s == NULL) { - CREATE (s, struct storage, 1); - memset (s, 0, sizeof (struct storage)); + CREATE(s, struct storage, 1); + memset(s, 0, sizeof(struct storage)); s->account_id = account_id; - numdb_insert (storage_db, s->account_id, s); + numdb_insert(storage_db, s->account_id, s); } return s; } //--------------------------------------------------------- // 倉庫データを読み込む -int inter_storage_init (void) +int inter_storage_init(void) { char line[65536]; - int c = 0, tmp_int; + int c = 0, tmp_int; struct storage *s; FILE *fp; - storage_db = numdb_init (); + storage_db = numdb_init(); - fp = fopen_ (storage_txt, "r"); + fp = fopen_(storage_txt, "r"); if (fp == NULL) { - printf ("cant't read : %s\n", storage_txt); + printf("cant't read : %s\n", storage_txt); return 1; } - while (fgets (line, 65535, fp)) + while (fgets(line, 65535, fp)) { - sscanf (line, "%d", &tmp_int); - CREATE (s, struct storage, 1); + sscanf(line, "%d", &tmp_int); + CREATE(s, struct storage, 1); s->account_id = tmp_int; - if (s->account_id > 0 && storage_fromstr (line, s) == 0) + if (s->account_id > 0 && storage_fromstr(line, s) == 0) { - numdb_insert (storage_db, s->account_id, s); + numdb_insert(storage_db, s->account_id, s); } else { - printf ("int_storage: broken data [%s] line %d\n", storage_txt, + printf("int_storage: broken data [%s] line %d\n", storage_txt, c); - free (s); + free(s); } c++; } - fclose_ (fp); + fclose_(fp); return 0; } static -void storage_db_final (db_key_t k, db_val_t data, va_list ap) +void storage_db_final(db_key_t k, db_val_t data, va_list ap) { struct storage *p = (struct storage *) data; if (p) - free (p); + free(p); } -void inter_storage_final (void) +void inter_storage_final(void) { - numdb_final (storage_db, storage_db_final); + numdb_final(storage_db, storage_db_final); return; } static -void inter_storage_save_sub (db_key_t key, db_val_t data, va_list ap) +void inter_storage_save_sub(db_key_t key, db_val_t data, va_list ap) { char line[65536]; FILE *fp; - storage_tostr (line, (struct storage *) data); - fp = va_arg (ap, FILE *); + storage_tostr(line, (struct storage *) data); + fp = va_arg(ap, FILE *); if (*line) - fprintf (fp, "%s\n", line); + fprintf(fp, "%s\n", line); } //--------------------------------------------------------- // 倉庫データを書き込む -int inter_storage_save (void) +int inter_storage_save(void) { FILE *fp; - int lock; + int lock; if (!storage_db) return 1; - if ((fp = lock_fopen (storage_txt, &lock)) == NULL) + if ((fp = lock_fopen(storage_txt, &lock)) == NULL) { - printf ("int_storage: cant write [%s] !!! data is lost !!!\n", + printf("int_storage: cant write [%s] !!! data is lost !!!\n", storage_txt); return 1; } - numdb_foreach (storage_db, inter_storage_save_sub, fp); - lock_fclose (fp, storage_txt, &lock); + numdb_foreach(storage_db, inter_storage_save_sub, fp); + lock_fclose(fp, storage_txt, &lock); // printf("int_storage: %s saved.\n",storage_txt); return 0; } // 倉庫データ削除 -int inter_storage_delete (int account_id) +int inter_storage_delete(int account_id) { struct storage *s = - (struct storage *) numdb_search (storage_db, account_id); + (struct storage *) numdb_search(storage_db, account_id); if (s) { - numdb_erase (storage_db, account_id); - free (s); + numdb_erase(storage_db, account_id); + free(s); } return 0; } @@ -236,25 +235,25 @@ int inter_storage_delete (int account_id) // 倉庫データの送信 static -int mapif_load_storage (int fd, int account_id) +int mapif_load_storage(int fd, int account_id) { - struct storage *s = account2storage (account_id); - WFIFOW (fd, 0) = 0x3810; - WFIFOW (fd, 2) = sizeof (struct storage) + 8; - WFIFOL (fd, 4) = account_id; - memcpy (WFIFOP (fd, 8), s, sizeof (struct storage)); - WFIFOSET (fd, WFIFOW (fd, 2)); + struct storage *s = account2storage(account_id); + WFIFOW(fd, 0) = 0x3810; + WFIFOW(fd, 2) = sizeof(struct storage) + 8; + WFIFOL(fd, 4) = account_id; + memcpy(WFIFOP(fd, 8), s, sizeof(struct storage)); + WFIFOSET(fd, WFIFOW(fd, 2)); return 0; } // 倉庫データ保存完了送信 static -int mapif_save_storage_ack (int fd, int account_id) +int mapif_save_storage_ack(int fd, int account_id) { - WFIFOW (fd, 0) = 0x3811; - WFIFOL (fd, 2) = account_id; - WFIFOB (fd, 6) = 0; - WFIFOSET (fd, 7); + WFIFOW(fd, 0) = 0x3811; + WFIFOL(fd, 2) = account_id; + WFIFOB(fd, 6) = 0; + WFIFOSET(fd, 7); return 0; } @@ -263,29 +262,29 @@ int mapif_save_storage_ack (int fd, int account_id) // 倉庫データ要求受信 static -int mapif_parse_LoadStorage (int fd) +int mapif_parse_LoadStorage(int fd) { - mapif_load_storage (fd, RFIFOL (fd, 2)); + mapif_load_storage(fd, RFIFOL(fd, 2)); return 0; } // 倉庫データ受信&保存 static -int mapif_parse_SaveStorage (int fd) +int mapif_parse_SaveStorage(int fd) { struct storage *s; - int account_id = RFIFOL (fd, 4); - int len = RFIFOW (fd, 2); - if (sizeof (struct storage) != len - 8) + int account_id = RFIFOL(fd, 4); + int len = RFIFOW(fd, 2); + if (sizeof(struct storage) != len - 8) { - printf ("inter storage: data size error %d %d\n", - sizeof (struct storage), len - 8); + printf("inter storage: data size error %d %d\n", + sizeof(struct storage), len - 8); } else { - s = account2storage (account_id); - memcpy (s, RFIFOP (fd, 8), sizeof (struct storage)); - mapif_save_storage_ack (fd, account_id); + s = account2storage(account_id); + memcpy(s, RFIFOP(fd, 8), sizeof(struct storage)); + mapif_save_storage_ack(fd, account_id); } return 0; } @@ -295,15 +294,15 @@ int mapif_parse_SaveStorage (int fd) // ・パケット長データはinter.cにセットしておくこと // ・パケット長チェックや、RFIFOSKIPは呼び出し元で行われるので行ってはならない // ・エラーなら0(false)、そうでないなら1(true)をかえさなければならない -int inter_storage_parse_frommap (int fd) +int inter_storage_parse_frommap(int fd) { - switch (RFIFOW (fd, 0)) + switch (RFIFOW(fd, 0)) { case 0x3010: - mapif_parse_LoadStorage (fd); + mapif_parse_LoadStorage(fd); break; case 0x3011: - mapif_parse_SaveStorage (fd); + mapif_parse_SaveStorage(fd); break; default: return 0; |