Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb0963210e | ||
|
|
30ea96f418 | ||
|
|
96f8486306 | ||
|
|
31ebae050b | ||
|
|
794ac41a41 | ||
|
|
103805998c | ||
|
|
f5b8424266 | ||
|
|
3058ad6002 | ||
|
|
b5e06c9a43 | ||
|
|
6924dc9b49 | ||
|
|
e8ace59fcd |
@@ -0,0 +1,56 @@
|
||||
# 材料与消耗品 2000 叠放:实现与验收
|
||||
|
||||
更新时间:2026-10-27。协议 `mt20261030`。已完成双端开发、打包、CH5隔离验收及203正式部署,正式登录已开放。新旧协议不能混用,用户必须升级客户端。
|
||||
|
||||
## 规则与协议
|
||||
|
||||
`port_material_stack_policy.h` 已接入运行时。允许叠放且没有禁止叠放标记的 USE、AUTOUSE、MATERIAL、METIN、RESOURCE、BLEND、EXTRACT,以及实际加载的强化/Cube 配方材料,上限为2000;其他物品保留200。禁止叠放优先,非叠放奖励逐件创建,不修改 proto 标记。生产配置审查清单含854个物品编号,部署机保存 `material-catalogue-production.json`。
|
||||
|
||||
物品数量线路使用 uint16,内部数量及 item 存档使用32位;金币和累计奖励计算保持宽类型。槽位、商品条目数等字段未扩大。背包、仓库、商城仓库、交易、NPC/玩家商店及装备观察结构已经同步;离线商店原有数量为32位,保留该宽度。
|
||||
|
||||
合堆校验原始编号、动态标记、插槽、属性、完整69字节扩展状态及持久化属性锁;锁定或交易中物品拒绝合堆。拆分/丢弃/仓库拆分先完成新物品创建和元数据复制,失败时不扣源数量。属性锁读取失败时拒绝合堆或拆分。
|
||||
|
||||
客户端在登录游戏核心和选择角色前发送版本,服务端在登录/选角/物品加载前拒绝旧版或缺失版本,状态为 VERSION;新版登录页显示升级提示。四位拆分/出售输入与实际物品数量对应。
|
||||
|
||||
## 已通过的隔离验收
|
||||
|
||||
- 199/200/201/255/256/1999/2000 边界;满组拒绝、拆分1000、重新合并、丢弃256、2001非法输入。
|
||||
- 同时运行两个真实客户端,1744材料交易并退回,核对数量;交易后材料按既有规则进入强化材料专用背包。
|
||||
- 普通仓库2000/1744存取、部分拆分与合并、满组拒绝;商城仓库2000取回。
|
||||
- NPC商店购买一组2000,分两次出售256及1744;奖励4001按组发放,不截断。
|
||||
- 属性追加2000→1999,转属性2000→1999,自动洗练继续准确扣除并停止。
|
||||
- Cube配方从单组2000扣除512成功批量制作,再扣除256进行零成功配方,余量1232,产出仅为成功的2件。
|
||||
- game/db重启后数量一致;宽存档回退模式保留整组2000移动,限制新增长200,拆分失败不损失数量。
|
||||
- Mac Android模拟器实际登录,读取2000和256,拆分为两组1000再合并为2000;最终macOS .app真实登录读取2000及256并完成渲染。
|
||||
- 43项Cube回归、14项商店回归、材料规则与实际合堆/拆分元数据检查。旧测试桩的8位数量和过时接口已同步修正;测试边界替身不等于全部正式流程已联机验收。
|
||||
|
||||
## 上线与回退
|
||||
|
||||
`tools/material-stack/migrate.py` 迁移 item、item_orphan_quarantine、shop_item 数量列为 INT UNSIGNED,保持默认值/非空及索引,并比较行数、数量总和及包含全部字段的数据指纹。重复执行不缩窄或重写物品。item_award 已是32位。
|
||||
|
||||
`cluster.py` 按实际 DB_PORT 枚举进程和二进制,维护停服后备份数据库/配置/现役二进制,成套更新 game/db,先以验收账号白名单启动。生产CH1—CH4、auth、game99使用DB15000;CH5及测试auth使用隔离DB15040,不能只按频道编号判断部署范围。候选game/db必须配套重建libsql,不能沿用可能存在ABI不一致的预编译库。
|
||||
|
||||
上线后已有超过200的物品时,严禁回到旧二进制或缩窄数据库。`cluster.py fallback` 使用同一宽协议候选并设置 `PORT_MATERIAL_STACK_LEGACY_MODE=1`,只停止新增长,保留存量的读取、移动和扣除。
|
||||
|
||||
## 正式上线记录
|
||||
|
||||
- 正式14个game/auth核心与db成套更新;CH5隔离服两个活动核心与独立db同步更新。另一个未运行的隔离crosscore路径也指向新版;共19个配置二进制路径逐一核对SHA256。
|
||||
- 正式三个数量列完成迁移;item表245行/5300件、隔离清理表1行/1件、shop_item表325行/2912件,迁移前后相同,完整数据指纹相同。重复执行迁移验证通过。
|
||||
- 新建专用验收账号,正式背包合并/拆分、洗练扣除、仓库存取、game/db重启、CH1→CH2→CH1往返通过。旧原生客户端在角色加载前明确收到VERSION。
|
||||
- 正式原有245件物品逐ID核对,归属、位置、编号和数量全部不变;验收道具单独属于新建账号。
|
||||
- Mac上的Android模拟器安装最终APK后连接正式服:2000→1000+1000→2000,前后完整抽样数量一致。最终macOS.app在真实服务端读取2000和256并完成渲染;签名完整性检查通过。
|
||||
- 追加的满背包验收通过:Cube拒绝时材料和产出不变(本轮未逐笔核对金币);批量开箱拒绝时不扣宝箱;2001奖励落地后腾出空间拾取,总数2001;腾出空间后两箱产生4000道具,每组不超过2000。
|
||||
- 强化从专用背包的2000材料组准确扣1。修复了旧强化只查普通背包的问题,普通/卷轴强化共用先预检再扣除的材料流程;重复材料编号累计校验,材料不足或锁定时不部分扣除。
|
||||
- 批量开箱的客户端中文奖励提示已修复,最终实测4000奖励无编码异常。NPC商店2000买入/256与1744分次出售、玩家商店1744购买并交易退回、落地1000拾取合堆均通过。
|
||||
- 临时测试任务、配方覆盖、商店、满背包填充物已清理;正式和隔离集群的验收白名单已解除,保持新协议版本门槛。
|
||||
|
||||
部署与备份:203 `/root/deploy-features/20261026-stack2000/backup-production-20261027/`。发布进程、迁移结果、配置路径和校验结果保存为同目录上一级的 `release-opened-20261027.json`;私密账号文件不进入交付记录或Git。
|
||||
|
||||
服务端game SHA256:`3a89fa1e13c7f0fa0270bc30969438fe3103aa5ffdacb172b2f86fa71a387f20`。
|
||||
服务端db SHA256:`b23eb7e1de7fc94560848791c154b0f76301239386f8bf11fdcec9ab672c50e4`。
|
||||
|
||||
## 验收边界
|
||||
|
||||
离线商店原有 `PortOfflineShopEconomyReady()==false` 硬开关保持关闭,不能把未发生的离线购买记为联机通过。43项Cube、14项商店、10项宝箱界面回归和材料规则/元数据/强化扣料检查通过;替身边界和此前资源/Wiki回归失败不表示整个游戏完整回归全部通过。手工向旧item_award表写入超出单组上限的批量记录未作联机验收;本轮已验证正常2000仓库及4001游戏奖励的分组通路。
|
||||
|
||||
macOS包为本地ad-hoc签名,未做Developer ID公证。Android APK包含程序,资源沿用现有客户端。本轮最终APK在Mac模拟器完成正式服联机验收;手机中途断开,最后一次中文提示修复后的APK未能再次覆盖安装到真机,不能计为最终真机验收。
|
||||
+4
-12
@@ -1,5 +1,5 @@
|
||||
CC=clang-devel
|
||||
CXX=clang++-devel
|
||||
CC ?= clang-devel
|
||||
CXX ?= clang++-devel
|
||||
|
||||
PLATFORM = $(shell file /bin/ls | cut -d' ' -f3 | cut -d'-' -f1)
|
||||
BSD_VERSION = $(shell uname -v 2>&1 | cut -d' ' -f2 | cut -d'.' -f1)
|
||||
@@ -11,19 +11,16 @@ default: libthecore libpoly libgame liblua libsql libserverkey game db
|
||||
|
||||
libthecore: .
|
||||
@touch $@/src/Depend
|
||||
$(MAKE) -C $@/src dep
|
||||
$(MAKE) -C $@/src clean
|
||||
$(MAKE) -C $@/src
|
||||
|
||||
libpoly: .
|
||||
@touch $@/Depend
|
||||
$(MAKE) -C $@ dep
|
||||
$(MAKE) -C $@ clean
|
||||
$(MAKE) -C $@
|
||||
|
||||
libgame: .
|
||||
@touch $@/src/Depend
|
||||
$(MAKE) -C $@/src dep
|
||||
$(MAKE) -C $@/src clean
|
||||
$(MAKE) -C $@/src
|
||||
|
||||
@@ -33,28 +30,23 @@ liblua: .
|
||||
|
||||
libsql: .
|
||||
@touch $@/Depend
|
||||
$(MAKE) -C $@ dep
|
||||
$(MAKE) -C $@ clean
|
||||
$(MAKE) -C $@
|
||||
|
||||
libserverkey: .
|
||||
@touch $@/Depend
|
||||
$(MAKE) -C $@ dep
|
||||
$(MAKE) -C $@ clean
|
||||
$(MAKE) -C $@
|
||||
|
||||
game: .
|
||||
@touch $@/src/Depend
|
||||
$(MAKE) -C $@/src dep
|
||||
$(MAKE) -C $@/src clean
|
||||
# $(MAKE) -C $@/src limit_time
|
||||
# $(MAKE) -C $@/src
|
||||
$(MAKE) -C $@/src
|
||||
|
||||
db: .
|
||||
@touch $@/src/Depend
|
||||
$(MAKE) -C $@/src dep
|
||||
$(MAKE) -C $@/src clean
|
||||
# $(MAKE) -C $@/src
|
||||
$(MAKE) -C $@/src
|
||||
|
||||
all:
|
||||
@echo "--------------------------------------"
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
#pragma once
|
||||
#include "cube_recipe.h"
|
||||
#include "economy.h"
|
||||
#include <array>
|
||||
#include <functional>
|
||||
|
||||
// Candidate DB-side batch contract. Not a client packet or permission to mutate
|
||||
// a live actor. A DB coordinator must first establish the matching durable fence.
|
||||
namespace PortCube {
|
||||
struct Item {
|
||||
PortEconomy::Reward value;
|
||||
uint16_t cell=0;
|
||||
bool usable=true;
|
||||
};
|
||||
struct Batch {
|
||||
uint32_t account=0,player=0;
|
||||
uint64_t epoch=0,gold=0;
|
||||
std::string owner,token;
|
||||
Recipe recipe;
|
||||
unsigned attempts=0;
|
||||
std::vector<Item> inventory;
|
||||
// Factory-created templates with reserved, never-reused IDs. No item rows
|
||||
// have been created yet; count=1 is replaced only by successful output.
|
||||
std::vector<PortEconomy::Reward> rewards;
|
||||
};
|
||||
inline bool Identity(const std::string& s) {
|
||||
if(s.size()!=32||s==std::string(32,'0'))return false;
|
||||
return std::all_of(s.begin(),s.end(),[](char c){return (c>='0'&&c<='9')||(c>='a'&&c<='f');});
|
||||
}
|
||||
inline bool Validate(const Batch& b) {
|
||||
Recipe recipe=b.recipe;
|
||||
if(!b.account||!b.player||!b.epoch||!Identity(b.owner)||!Identity(b.token)||
|
||||
b.gold>uint64_t(PortEconomy::GoldLimit)||!Normalize(recipe)||recipe.id>MaxRecipes||recipe.copy||
|
||||
!b.attempts||b.attempts>MaxAttempts||b.inventory.size()>225)return false;
|
||||
// Only canonical normalized recipes are accepted. No uninitialized copy
|
||||
// semantics, duplicate requirements or reordered NPCs enter the journal.
|
||||
if(recipe.npcs!=b.recipe.npcs||recipe.materials.size()!=b.recipe.materials.size()||
|
||||
!std::equal(recipe.materials.begin(),recipe.materials.end(),b.recipe.materials.begin(),
|
||||
[](const Material& a,const Material& c){return a.vnum==c.vnum&&a.count==c.count;}))return false;
|
||||
const uint64_t maximum=uint64_t(recipe.rewardCount)*b.attempts;
|
||||
const unsigned stacks=recipe.stackable?unsigned((maximum+1999)/2000):unsigned(maximum);
|
||||
if(b.rewards.size()!=stacks||stacks>100)return false;
|
||||
std::set<uint32_t> ids;int last=-1;
|
||||
for(const auto& i:b.inventory) {
|
||||
if(!i.value.id||!i.value.vnum||!i.value.count||i.value.count>2000||i.cell>=225||
|
||||
int(i.cell)<=last||!ids.insert(i.value.id).second)return false;
|
||||
last=i.cell;
|
||||
}
|
||||
for(const auto& r:b.rewards)if(!r.id||r.vnum!=recipe.reward||r.count!=1||!ids.insert(r.id).second)return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Explicit little-endian bounded codec, never sizeof(Batch) or padded structs.
|
||||
// It is deliberately separate from the legacy client/game protocol.
|
||||
struct Writer {
|
||||
std::string data;
|
||||
void n(uint64_t value,unsigned bytes){for(unsigned i=0;i<bytes;++i){data+=char(value&255);value>>=8;}}
|
||||
void s(const std::string& text){n(text.size(),2);data+=text;}
|
||||
void reward(const PortEconomy::Reward& r){
|
||||
n(r.id,4);n(r.vnum,4);n(r.count,4);
|
||||
for(auto x:r.sockets)n(uint32_t(x),4);
|
||||
for(unsigned i=0;i<7;++i){n(r.types[i],1);n(uint16_t(r.values[i]),2);}
|
||||
for(auto x:r.extra)n(x,1);
|
||||
}
|
||||
void items(const std::vector<Item>& rows){n(rows.size(),2);for(const auto& i:rows){reward(i.value);n(i.cell,2);n(i.usable,1);}}
|
||||
};
|
||||
struct Reader {
|
||||
const std::string& data;size_t at=0;bool ok=true;
|
||||
explicit Reader(const std::string& value):data(value){}
|
||||
uint64_t n(unsigned bytes){
|
||||
if(!ok||bytes>8||at>data.size()||bytes>data.size()-at){ok=false;return 0;}
|
||||
uint64_t value=0;for(unsigned i=0;i<bytes;++i)value|=uint64_t(uint8_t(data[at++]))<<(8*i);return value;
|
||||
}
|
||||
std::string s(unsigned maximum){const auto count=n(2);if(!ok||count>maximum||count>data.size()-at){ok=false;return {};}
|
||||
std::string value=data.substr(at,size_t(count));at+=size_t(count);return value;}
|
||||
PortEconomy::Reward reward(){
|
||||
PortEconomy::Reward r;r.id=uint32_t(n(4));r.vnum=uint32_t(n(4));r.count=uint32_t(n(4));
|
||||
for(auto& x:r.sockets){uint32_t bits=uint32_t(n(4));std::memcpy(&x,&bits,4);}
|
||||
for(unsigned i=0;i<7;++i){r.types[i]=uint8_t(n(1));uint16_t bits=uint16_t(n(2));std::memcpy(&r.values[i],&bits,2);}
|
||||
for(auto& x:r.extra)x=uint8_t(n(1));return r;
|
||||
}
|
||||
std::vector<Item> items(){
|
||||
const auto count=n(2);if(count>225){ok=false;return {};}
|
||||
std::vector<Item> rows;for(unsigned i=0;i<count&&ok;++i){Item item;item.value=reward();item.cell=uint16_t(n(2));auto usable=n(1);if(usable>1)ok=false;item.usable=usable!=0;rows.push_back(item);}return rows;
|
||||
}
|
||||
};
|
||||
inline std::string Encode(const Batch& b) {
|
||||
Writer w;w.n(1,4);w.n(b.account,4);w.n(b.player,4);w.n(b.epoch,8);w.n(b.gold,8);w.s(b.owner);w.s(b.token);
|
||||
const auto& r=b.recipe;w.n(r.id,4);w.n(r.reward,4);w.n(r.rewardCount,4);w.n(r.gold,4);w.n(r.percent,1);w.n(r.stackable,1);w.n(r.copy,1);w.s(r.category);
|
||||
w.n(r.npcs.size(),1);for(auto n:r.npcs)w.n(n,4);
|
||||
w.n(r.materials.size(),1);for(auto m:r.materials){w.n(m.vnum,4);w.n(m.count,4);}
|
||||
w.n(b.attempts,1);w.items(b.inventory);w.n(b.rewards.size(),1);for(const auto& item:b.rewards)w.reward(item);
|
||||
return w.data;
|
||||
}
|
||||
inline bool Decode(const std::string& data,Batch& out) {
|
||||
if(data.size()>40000)return false;
|
||||
Reader r(data);Batch b;if(r.n(4)!=1)return false;
|
||||
b.account=uint32_t(r.n(4));b.player=uint32_t(r.n(4));b.epoch=r.n(8);b.gold=r.n(8);b.owner=r.s(32);b.token=r.s(32);
|
||||
auto& recipe=b.recipe;recipe.id=uint32_t(r.n(4));recipe.reward=uint32_t(r.n(4));recipe.rewardCount=uint32_t(r.n(4));recipe.gold=uint32_t(r.n(4));recipe.percent=unsigned(r.n(1));
|
||||
auto stack=r.n(1),copy=r.n(1);if(stack>1||copy>1)return false;recipe.stackable=stack!=0;recipe.copy=copy!=0;recipe.category=r.s(24);
|
||||
auto count=r.n(1);if(count>128)return false;for(unsigned i=0;i<count&&r.ok;++i)recipe.npcs.push_back(uint32_t(r.n(4)));
|
||||
count=r.n(1);if(count>5)return false;for(unsigned i=0;i<count&&r.ok;++i){Material m;m.vnum=uint32_t(r.n(4));m.count=uint32_t(r.n(4));recipe.materials.push_back(m);}
|
||||
b.attempts=unsigned(r.n(1));b.inventory=r.items();count=r.n(1);if(count>100)return false;for(unsigned i=0;i<count&&r.ok;++i)b.rewards.push_back(r.reward());
|
||||
if(!r.ok||r.at!=data.size()||!Validate(b)||Encode(b)!=data)return false;out=std::move(b);return true;
|
||||
}
|
||||
struct Proto {unsigned size=0;bool stackable=false;};
|
||||
using Lookup=std::function<Proto(uint32_t)>;
|
||||
struct Settlement {
|
||||
std::string result="invalid";
|
||||
unsigned successes=0;
|
||||
uint64_t fee=0;
|
||||
std::vector<Take> takes;
|
||||
std::vector<Item> awards;
|
||||
};
|
||||
inline Settlement SettlePlan(const Batch& b,const std::string& rolls,const Lookup& lookup) {
|
||||
Settlement s;if(!Validate(b)||rolls.size()!=b.attempts)return s;
|
||||
for(unsigned char roll:rolls){if(roll<1||roll>100)return s;s.successes+=roll<=b.recipe.percent;}
|
||||
const auto reward=lookup(b.recipe.reward);
|
||||
if(reward.size<1||reward.size>3||reward.stackable!=b.recipe.stackable){s.result="item_proto";return s;}
|
||||
std::vector<Input> inputs;for(const auto& i:b.inventory)inputs.push_back({i.value.id,i.value.vnum,i.value.count,i.cell,i.usable});
|
||||
const auto p=Preview(b.recipe,b.attempts,inputs,int64_t(b.gold));
|
||||
if(!p.valid)return s;
|
||||
if(!p.materialsOK){s.result="materials_missing";return s;}
|
||||
if(!p.goldOK){s.result="gold_missing";return s;}
|
||||
auto inventory=b.inventory;
|
||||
auto occupy=[&](const std::vector<Item>& rows,std::array<bool,225>& used)->bool {
|
||||
for(const auto& i:rows) {
|
||||
if(!i.value.count)continue;const auto proto=lookup(i.value.vnum);
|
||||
if(proto.size<1||proto.size>3||(!proto.stackable&&i.value.count!=1)||(i.cell%45)/5+proto.size>9)return false;
|
||||
for(unsigned j=0;j<proto.size;++j){const unsigned at=i.cell+5*j;if(at>=225||used[at])return false;used[at]=true;}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
std::array<bool,225> used={};
|
||||
if(!occupy(inventory,used)){s.result="inventory_invalid";return s;}
|
||||
for(const auto& take:p.takes)for(auto& i:inventory)if(i.value.id==take.id)i.value.count-=take.count;
|
||||
used.fill(false);if(!occupy(inventory,used))return s;
|
||||
uint64_t remaining=uint64_t(b.recipe.rewardCount)*s.successes;unsigned next=0;
|
||||
while(remaining) {
|
||||
unsigned cell=225;
|
||||
for(unsigned at=0;at<225;++at) {
|
||||
if((at%45)/5+reward.size>9)continue;bool free=true;
|
||||
for(unsigned j=0;j<reward.size;++j)if(used[at+5*j])free=false;
|
||||
if(free){cell=at;break;}
|
||||
}
|
||||
if(cell==225){s.awards.clear();s.result="capacity_full";return s;}
|
||||
Item item;item.value=b.rewards[next++];item.value.count=uint32_t(std::min(remaining,uint64_t(reward.stackable?2000:1)));item.cell=uint16_t(cell);
|
||||
for(unsigned j=0;j<reward.size;++j)used[cell+5*j]=true;
|
||||
remaining-=item.value.count;s.awards.push_back(item);
|
||||
}
|
||||
s.result="ok";s.fee=p.gold;s.takes=p.takes;return s;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include "cube_handshake.h"
|
||||
namespace PortCube {
|
||||
class CraftFlow {
|
||||
public:
|
||||
enum Stage {Idle,WaitPrepare,WaitExecute,Complete,Held};
|
||||
private:
|
||||
Handshake identity;Stage stage=Idle;CraftReceipt receipt;
|
||||
public:
|
||||
Stage State()const{return stage;}
|
||||
const CraftReceipt& Receipt()const{return receipt;}
|
||||
bool MayRetry()const{return stage==WaitPrepare||stage==WaitExecute;}
|
||||
bool Start(const Handshake& bound,bool cleanFrozen,bool sourceAcknowledged) {
|
||||
auto f=bound;f.message=Message::Prepare;f.status=Status::None;f.body.clear();
|
||||
if(stage!=Idle||!cleanFrozen||!sourceAcknowledged||!ValidHandshake(f))return false;identity=std::move(f);stage=WaitPrepare;return true;
|
||||
}
|
||||
Handshake Request()const{auto f=identity;f.message=stage==WaitExecute?Message::Execute:Message::Prepare;return f;}
|
||||
void Invalidate(){if(stage!=Idle)stage=Held;}
|
||||
bool Answer(const Handshake& f,const Batch& b,const Lookup& lookup) {
|
||||
if(b.account!=identity.account||b.player!=identity.player||b.epoch!=identity.epoch||b.owner!=identity.owner||b.token!=identity.token)return false;
|
||||
if(!ValidHandshake(f)||f.message!=Message::CraftAnswer||!SameIdentity(identity,f)||f.cookie!=identity.cookie||!MayRetry()&&stage!=Complete)return false;
|
||||
if(f.status==Status::Held)return MayRetry();
|
||||
if(f.status==Status::Prepared){if(stage==WaitPrepare){stage=WaitExecute;return true;}return stage==WaitExecute;}
|
||||
if(f.status!=Status::Complete||stage==WaitPrepare)return false;
|
||||
CraftReceipt result;if(!DecodeCraftReceipt(f.body,result)||!ValidateCraftReceipt(b,result,lookup))return false;
|
||||
if(stage==Complete){if(EncodeCraftReceipt(receipt)==f.body)return true;stage=Held;return false;}
|
||||
receipt=std::move(result);stage=Complete;return true; // never authorizes local assets, saves, ACK or thaw
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include "cube_batch.h"
|
||||
|
||||
namespace PortCube {
|
||||
// Transport-independent correlation core. The runtime adapter must bind session
|
||||
// to the actual game peer/character generation and not accept it from a client.
|
||||
class Drain {
|
||||
std::string identity;
|
||||
uint64_t session=0,mainEpoch=0,asyncEpoch=0;
|
||||
unsigned pass=0;
|
||||
bool asyncDone=false,failed=false;
|
||||
public:
|
||||
bool Start(const Batch& batch,uint64_t ownerSession,uint64_t main,uint64_t async) {
|
||||
if(!identity.empty()||!Validate(batch)||!ownerSession)return false;
|
||||
identity=Encode(batch);session=ownerSession;mainEpoch=main;asyncEpoch=async;return true;
|
||||
}
|
||||
// Return 1 only for the FIRST main barrier: adapter must enqueue the second
|
||||
// main FIFO barrier and the async FIFO barrier after processing that callback.
|
||||
// Numbered passes prevent a duplicate first callback completing the drain.
|
||||
unsigned Main(const Batch& b,uint64_t sourceSession,unsigned number,bool error) {
|
||||
if(identity!=Encode(b)||sourceSession!=session||number!=pass+1||number>2)return 0;
|
||||
failed|=error;pass=number;return pass==1?1:2;
|
||||
}
|
||||
bool Async(const Batch& b,uint64_t sourceSession,bool error) {
|
||||
if(identity!=Encode(b)||sourceSession!=session||pass<1||asyncDone)return false;
|
||||
failed|=error;asyncDone=true;return true;
|
||||
}
|
||||
bool Matches(const Batch& b,uint64_t sourceSession)const{return !identity.empty()&&identity==Encode(b)&&sourceSession==session;}
|
||||
bool Complete()const{return pass==2&&asyncDone;}
|
||||
bool Clean(uint64_t main,uint64_t async)const{return Complete()&&!failed&&main==mainEpoch&&async==asyncEpoch;}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
#pragma once
|
||||
#include "cube_store.h"
|
||||
#include "cube_drain.h"
|
||||
#include "cube_gold_intent.h"
|
||||
#include "cube_owner_types.h"
|
||||
|
||||
namespace PortCube {
|
||||
// DB-side lifecycle, not an actor-freeze implementation. Only a trusted runtime
|
||||
// coordinator may call these methods after binding the session and all owners.
|
||||
template<class DB> class FenceStore {
|
||||
DB& db;Lookup lookup;
|
||||
using Rows=PortEconomy::Rows;
|
||||
static std::string N(uint64_t n){return std::to_string(n);}
|
||||
static std::string X(const std::string& s){return "X'"+PortEconomy::Hex(s.data(),s.size())+"'";}
|
||||
bool Q(const std::string& sql,Rows& rows){return db.Query(sql,rows)&&!db.warnings;}
|
||||
bool Run(const std::string& sql){Rows rows;return Q(sql,rows);}
|
||||
bool Change(const std::string& sql){return Run(sql)&&db.affected==1;}
|
||||
struct Guard {DB& db;~Guard(){db.Rollback();}};
|
||||
bool Lock(const Batch& b,Rows& rows) {
|
||||
if(!Run("INSERT INTO port_economy_account_lock(account) VALUES("+N(b.account)+") ON DUPLICATE KEY UPDATE account=VALUES(account)")||
|
||||
!Q("SELECT account FROM port_economy_account_lock WHERE account="+N(b.account)+" FOR UPDATE",rows)||rows.size()!=1)return false;
|
||||
return Q("SELECT account,epoch,owner,request,phase,body,image,drain_state FROM port_cube_fences WHERE pid="+N(b.player)+" FOR UPDATE",rows);
|
||||
}
|
||||
bool Same(const Batch& b,const Rows& rows)const {
|
||||
return rows.size()==1&&rows[0].size()==8&&rows[0][0]==N(b.account)&&rows[0][1]==N(b.epoch)&&rows[0][2]==b.owner&&rows[0][3]==b.token&&rows[0][5]==Encode(b);
|
||||
}
|
||||
static bool Signed(const std::string& s,int64_t low,int64_t high,int64_t& out) {
|
||||
if(s.empty())return false;const bool negative=s[0]=='-';uint64_t n=0;
|
||||
if(!PortEconomy::Number(negative?s.substr(1):s,n,uint64_t(negative?-low:high)))return false;
|
||||
out=negative?-int64_t(n):int64_t(n);return out>=low&&out<=high&&std::to_string(out)==s;
|
||||
}
|
||||
bool Image(const Batch& b,std::string& image) {
|
||||
Rows rows;uint64_t gold=0;
|
||||
if(!Q("SELECT gold FROM player WHERE id="+N(b.player)+" AND account_id="+N(b.account)+" FOR UPDATE",rows)||rows.size()!=1||rows[0].size()!=1||!PortEconomy::Number(rows[0][0],gold,PortEconomy::GoldLimit))return false;
|
||||
std::string columns="id,vnum,count,pos";for(unsigned i=0;i<3;++i)columns+=",socket"+N(i);
|
||||
for(unsigned i=0;i<7;++i)columns+=",attrtype"+N(i)+",attrvalue"+N(i);columns+=",port_extra";
|
||||
if(!Q("SELECT "+columns+" FROM item WHERE owner_id="+N(b.player)+" AND window='INVENTORY' AND pos<225 ORDER BY pos,id FOR UPDATE",rows)||rows.size()>225)return false;
|
||||
std::vector<Item> items;std::set<uint32_t> ids;std::array<bool,225> used={};int last=-1;
|
||||
for(const auto& row:rows) {
|
||||
if(row.size()!=22)return false;
|
||||
Item i;uint64_t n=0;int64_t signedValue=0;
|
||||
auto number=[&](unsigned field,uint64_t max)->bool {return PortEconomy::Number(row[field],n,max);};
|
||||
if(!number(0,UINT32_MAX)||!n)return false;i.value.id=uint32_t(n);
|
||||
if(!number(1,UINT32_MAX)||!n)return false;i.value.vnum=uint32_t(n);
|
||||
if(!number(2,2000)||!n)return false;i.value.count=uint32_t(n);
|
||||
if(!number(3,224))return false;i.cell=uint16_t(n);
|
||||
if(int(i.cell)<=last||!ids.insert(i.value.id).second)return false;last=i.cell;
|
||||
for(unsigned j=0;j<3;++j){if(!Signed(row[4+j],INT32_MIN,INT32_MAX,signedValue))return false;i.value.sockets[j]=int32_t(signedValue);}
|
||||
for(unsigned j=0;j<7;++j){if(!number(7+2*j,255))return false;i.value.types[j]=uint8_t(n);if(!Signed(row[8+2*j],INT16_MIN,INT16_MAX,signedValue))return false;i.value.values[j]=int16_t(signedValue);}
|
||||
if(row[21].size()!=69)return false;std::memcpy(i.value.extra,row[21].data(),69);
|
||||
const auto proto=lookup(i.value.vnum);if(proto.size<1||proto.size>3||(!proto.stackable&&i.value.count!=1)||(i.cell%45)/5+proto.size>9)return false;
|
||||
for(unsigned j=0;j<proto.size;++j){const unsigned cell=i.cell+5*j;if(cell>=225||used[cell])return false;used[cell]=true;}
|
||||
items.push_back(i);
|
||||
}
|
||||
Writer w;w.n(gold,8);w.items(items);image=std::move(w.data);return true;
|
||||
}
|
||||
public:
|
||||
enum Result { Retry, Refused, Done };
|
||||
FenceStore(DB& database,Lookup proto):db(database),lookup(std::move(proto)){}
|
||||
// cachedIds must include ALL owned dirty item IDs captured by the DB adapter
|
||||
// before eviction, not merely the normal-inventory recipe inputs.
|
||||
Result Begin(const Batch& b,const std::vector<uint32_t>& cachedIds,const std::function<bool(bool)>& ownership={}) {
|
||||
if(!Validate(b)||cachedIds.size()>4096)return Refused;
|
||||
BatchStore<DB> ready(db,lookup);if(!ready.Ready()||!db.Begin())return Retry;Guard guard{db};Rows rows;
|
||||
if(!Lock(b,rows))return Retry;
|
||||
if(Same(b,rows))return !ownership||ownership(true)?Done:Refused; // never invent missing ownership on replay
|
||||
if(!rows.empty()) {
|
||||
uint64_t previous=0;if(rows.size()!=1||rows[0].size()!=8||rows[0][4]!="RELEASED"||rows[0][3]==b.token||!PortEconomy::Number(rows[0][1],previous)||b.epoch<=previous)return Refused;
|
||||
}
|
||||
if(!Q("SELECT token FROM port_economy_pending WHERE pid="+N(b.player)+" FOR UPDATE",rows))return Retry;if(!rows.empty())return Refused;
|
||||
if(!Q("SELECT token FROM port_cube_requests WHERE token='"+b.token+"' FOR UPDATE",rows))return Retry;if(!rows.empty())return Refused;
|
||||
// The drain itself can survive a restart before Prepare. Reserve every
|
||||
// reward ID now, not only after RNG preparation, so boot cannot reuse it.
|
||||
for(const auto& reward:b.rewards) {
|
||||
if(!Q("SELECT id FROM item WHERE id="+N(reward.id)+" UNION ALL SELECT id FROM port_economy_custody WHERE id="+N(reward.id)+" UNION ALL SELECT id FROM port_economy_item_reservations WHERE id="+N(reward.id),rows))return Retry;
|
||||
if(!rows.empty())return Refused;
|
||||
if(!Change("INSERT INTO port_economy_item_reservations(id,request) VALUES("+N(reward.id)+",'"+b.token+"')"))return Retry;
|
||||
}
|
||||
std::set<uint32_t> ids;
|
||||
for(auto id:cachedIds){if(!id)return Refused;ids.insert(id);}
|
||||
for(const auto& i:b.inventory)ids.insert(i.value.id);for(const auto& i:b.rewards)ids.insert(i.id);
|
||||
if(!Q("SELECT id FROM item WHERE owner_id="+N(b.player)+" AND window NOT IN ('MALL','SAFEBOX') FOR UPDATE",rows))return Retry;
|
||||
if(rows.size()>4096)return Refused;
|
||||
for(const auto& row:rows){uint64_t id=0;if(row.size()!=1||!PortEconomy::Number(row[0],id,UINT32_MAX)||!id)return Retry;ids.insert(uint32_t(id));}
|
||||
const auto body=Encode(b);
|
||||
if(!Run("DELETE FROM port_cube_fences WHERE pid="+N(b.player)+" AND phase='RELEASED'")||
|
||||
!Change("INSERT INTO port_cube_fences(pid,account,epoch,owner,request,phase,body,image,drain_state) VALUES("+N(b.player)+","+N(b.account)+","+N(b.epoch)+",'"+b.owner+"','"+b.token+"','DRAINING',"+X(body)+",X'',0)"))return Retry;
|
||||
for(auto id:ids)if(!Change("INSERT INTO port_cube_item_fences(id,pid,epoch,request) VALUES("+N(id)+","+N(b.player)+","+N(b.epoch)+",'"+b.token+"')"))return Retry;
|
||||
if(ownership&&!ownership(false))return Refused;
|
||||
return db.Commit()?Done:Retry;
|
||||
}
|
||||
Result FinishDrain(const Batch& b,const Drain& drain,uint64_t session,uint64_t main,uint64_t async,bool stillOwner) {
|
||||
if(!Validate(b)||!drain.Matches(b,session)||!drain.Complete())return Refused;
|
||||
BatchStore<DB> ready(db,lookup);if(!ready.Ready()||!db.Begin())return Retry;Guard guard{db};Rows rows;
|
||||
if(!Lock(b,rows))return Retry;if(!Same(b,rows))return Refused;
|
||||
const char* phase=stillOwner&&drain.Clean(main,async)?"FROZEN":"ABORTED";
|
||||
if(rows[0][4]==phase&&rows[0][7]==(std::string(phase)=="FROZEN"?"1":"2"))return Done;
|
||||
if(rows[0][4]!="DRAINING")return Refused;
|
||||
if(!Change("UPDATE port_cube_fences SET phase='"+std::string(phase)+"',drain_state="+(phase==std::string("FROZEN")?"1":"2")+" WHERE pid="+N(b.player)+" AND phase='DRAINING'"))return Retry;
|
||||
return db.Commit()?Done:Retry;
|
||||
}
|
||||
Result AbortUnprepared(const Batch& b) {
|
||||
if(!Validate(b))return Refused;BatchStore<DB> ready(db,lookup);
|
||||
if(!ready.Ready()||!db.Begin())return Retry;Guard guard{db};Rows rows;
|
||||
if(!Lock(b,rows))return Retry;if(!Same(b,rows))return Refused;
|
||||
if(rows[0][4]=="ABORTED"&&rows[0][7]=="2")return Done;
|
||||
if(rows[0][4]!="FROZEN"||rows[0][7]!="1")return Refused;
|
||||
if(!Q("SELECT token FROM port_cube_requests WHERE token='"+b.token+"' FOR UPDATE",rows))return Retry;
|
||||
if(!rows.empty())return Refused; // an ambiguous prepare must be queried, not cancelled blindly
|
||||
if(!Change("UPDATE port_cube_fences SET phase='ABORTED',drain_state=2 WHERE pid="+N(b.player)+" AND phase='FROZEN'")||!db.Commit())return Retry;
|
||||
return Done;
|
||||
}
|
||||
Result Recover(uint32_t account,uint32_t player,Batch& batch,std::string& phase,std::string& image) {
|
||||
batch={};phase.clear();image.clear();if(!account||!player)return Refused;
|
||||
BatchStore<DB> ready(db,lookup);if(!ready.Ready()||!db.Begin())return Retry;Guard guard{db};Rows rows;
|
||||
if(!Q("SELECT account,epoch,owner,request,phase,body,image,drain_state FROM port_cube_fences WHERE pid="+N(player)+" AND account="+N(account)+" FOR UPDATE",rows))return Retry;
|
||||
if(rows.empty())return Refused;
|
||||
if(rows.size()!=1||rows[0].size()!=8||!Decode(rows[0][5],batch)||batch.account!=account||batch.player!=player||!Same(batch,rows)||rows[0][6].size()>40000)return Retry;
|
||||
const std::set<std::string> states={"DRAINING","FROZEN","ABORTED","RESYNC","RELEASED"};
|
||||
const auto& stage=rows[0][4];const auto& drained=rows[0][7];
|
||||
if(!states.count(stage)||(stage=="DRAINING"&&drained!="0")||(stage=="FROZEN"&&drained!="1")||(stage=="ABORTED"&&drained!="2")||((stage=="RESYNC"||stage=="RELEASED")&&drained!="1"&&drained!="2"))return Retry;
|
||||
phase=stage;image=rows[0][6];return Done;
|
||||
}
|
||||
Result Resync(const Batch& b,std::string& image,const std::function<bool(const std::string&)>& ownership={}) {
|
||||
image.clear();if(!Validate(b))return Refused;
|
||||
BatchStore<DB> ready(db,lookup);if(!ready.Ready()||!db.Begin())return Retry;Guard guard{db};Rows rows;
|
||||
if(!Lock(b,rows))return Retry;if(!Same(b,rows))return Refused;
|
||||
const auto phase=rows[0][4],drained=rows[0][7],saved=rows[0][6];
|
||||
if(!ownership){const int owner=OwnerReleaseStatus(db,b);if(owner<0)return Retry;if(!owner)return Refused;}
|
||||
if(phase!="ABORTED"&&phase!="FROZEN"&&phase!="RESYNC")return Refused;
|
||||
if(!Q("SELECT state FROM port_cube_requests WHERE token='"+b.token+"' AND account="+N(b.account)+" AND pid="+N(b.player)+" FOR UPDATE",rows))return Retry;
|
||||
if(drained!="1"&&drained!="2")return Refused;
|
||||
if((drained=="2"&&!rows.empty())||(drained=="1"&&(rows.size()!=1||rows[0].size()!=1||rows[0][0]!="DONE")))return Refused;
|
||||
{const int clear=GoldIntentsStatus(db,b);if(clear<0)return Retry;if(!clear)return Refused;}
|
||||
std::string current;if(!Image(b,current))return Retry;
|
||||
if(ownership&&!ownership(current))return Refused;
|
||||
if(ownership&&phase=="RESYNC"&&saved!=current)return Refused; // never replace an owner's previously issued image
|
||||
if(!Run("UPDATE port_cube_fences SET phase='RESYNC',image="+X(current)+" WHERE pid="+N(b.player))||!db.Commit())return Retry;
|
||||
image=std::move(current);return Done;
|
||||
}
|
||||
// ACK is the exact canonical image, not an FNV hash or a timeout. The game
|
||||
// adapter must verify it has applied that image to this still-frozen owner.
|
||||
Result Release(const Batch& b,const std::string& acknowledged,const std::function<bool(bool)>& ownership={}) {
|
||||
if(!Validate(b)||acknowledged.empty()||acknowledged.size()>40000)return Refused;
|
||||
BatchStore<DB> ready(db,lookup);if(!ready.Ready()||!db.Begin())return Retry;Guard guard{db};Rows rows;
|
||||
if(!Lock(b,rows))return Retry;if(!Same(b,rows)||rows[0][6]!=acknowledged)return Refused;
|
||||
if(!ownership){const int owner=OwnerReleaseStatus(db,b);if(owner<0)return Retry;if(!owner)return Refused;}
|
||||
if(rows[0][4]=="RELEASED")return !ownership||ownership(true)?Done:Refused;
|
||||
if(rows[0][4]!="RESYNC")return Refused;
|
||||
{const int clear=GoldIntentsStatus(db,b);if(clear<0)return Retry;if(!clear)return Refused;}
|
||||
std::string current;if(!Image(b,current))return Retry;if(current!=acknowledged)return Refused;
|
||||
// Trusted coordinator callback shares this account transaction. It must
|
||||
// validate current ownership and atomically archive/retire the lease.
|
||||
if(ownership&&!ownership(false))return Refused;
|
||||
if(!Run("DELETE FROM port_cube_item_fences WHERE pid="+N(b.player)+" AND epoch="+N(b.epoch)+" AND request='"+b.token+"'")||
|
||||
!Change("UPDATE port_cube_fences SET phase='RELEASED' WHERE pid="+N(b.player)+" AND phase='RESYNC'")||!db.Commit())return Retry;
|
||||
return Done;
|
||||
}
|
||||
// Resume preflight only. A historical Release replay does not reread current
|
||||
// assets; this check MUST lock and validate the current image anew, on the
|
||||
// same pinned connection/account transaction as the authority callback.
|
||||
Result CheckReleasedImage(const Batch& b,const std::string& expected,const std::function<bool()>& authority) {
|
||||
if(!Validate(b)||expected.empty()||expected.size()>40000||!authority)return Refused;
|
||||
BatchStore<DB> ready(db,lookup);if(!ready.Ready()||!db.Begin())return Retry;Guard guard{db};Rows rows;
|
||||
if(!Lock(b,rows))return Retry;
|
||||
if(!Same(b,rows)||rows[0][4]!="RELEASED"||rows[0][6]!=expected||rows[0][7]!="1")return Refused;
|
||||
{const int clear=GoldIntentsStatus(db,b);if(clear<0)return Retry;if(!clear)return Refused;}
|
||||
std::string current;if(!Image(b,current))return Retry;if(current!=expected||!authority())return Refused;
|
||||
return db.Commit()?Done:Retry;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
#pragma once
|
||||
#include "cube_store.h"
|
||||
#include "cube_gold_source.h"
|
||||
namespace PortCube {
|
||||
// Positive reward intents ONLY. Not a generic PointChange replacement, item
|
||||
// snapshot, permission to mint currency, or proof a source event is legitimate.
|
||||
constexpr unsigned GoldIntentLimit=1024,GoldIntentBytes=129;
|
||||
static_assert(GoldIntentLimit==GoldSourceLimit,"source manifest covers every intent sequence");
|
||||
struct GoldIntent {
|
||||
uint32_t account=0,player=0,sequence=0;
|
||||
uint64_t epoch=0,amount=0;
|
||||
uint8_t source=0; // trusted producer registry: 1 combat, 2 quest, 3 delivery
|
||||
std::string owner,request,event;
|
||||
};
|
||||
inline bool ValidGoldIntent(const GoldIntent& i) {
|
||||
return i.account&&i.player&&i.epoch&&i.sequence&&i.sequence<=GoldIntentLimit&&
|
||||
i.amount&&i.amount<=uint64_t(PortEconomy::GoldLimit)&&i.source>=1&&i.source<=3&&
|
||||
Identity(i.owner)&&Identity(i.request)&&Identity(i.event);
|
||||
}
|
||||
inline bool Matches(const GoldIntent& i,const Batch& b) {
|
||||
return i.account==b.account&&i.player==b.player&&i.epoch==b.epoch&&i.owner==b.owner&&i.request==b.token;
|
||||
}
|
||||
inline std::string EncodeGoldIntent(const GoldIntent& i) {
|
||||
if(!ValidGoldIntent(i))return {};
|
||||
Writer w;w.n(1,4);w.n(i.account,4);w.n(i.player,4);w.n(i.epoch,8);w.n(i.sequence,4);w.n(i.amount,8);w.n(i.source,1);
|
||||
w.data+=i.owner;w.data+=i.request;w.data+=i.event;return w.data;
|
||||
}
|
||||
inline bool DecodeGoldIntent(const std::string& bytes,GoldIntent& i) {
|
||||
i={};if(bytes.size()!=GoldIntentBytes)return false;Reader r(bytes);if(r.n(4)!=1)return false;
|
||||
GoldIntent out;out.account=uint32_t(r.n(4));out.player=uint32_t(r.n(4));out.epoch=r.n(8);out.sequence=uint32_t(r.n(4));out.amount=r.n(8);out.source=uint8_t(r.n(1));
|
||||
out.owner=bytes.substr(r.at,32);out.request=bytes.substr(r.at+32,32);out.event=bytes.substr(r.at+64,32);
|
||||
if(!r.ok||!ValidGoldIntent(out)||EncodeGoldIntent(out)!=bytes)return false;i=std::move(out);return true;
|
||||
}
|
||||
template<class DB> int GoldSchema(DB& db) {
|
||||
PortEconomy::Rows rows;
|
||||
const std::string names="('port_cube_gold_version','port_cube_gold_intents','port_cube_gold_sources')";
|
||||
if(!db.Query("SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN "+names,rows)||db.warnings||rows.size()!=1||rows[0].size()!=1)return -1;
|
||||
if(rows[0][0]=="0")return 0;
|
||||
if(rows[0][0]!="3"||!db.Query("SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA=DATABASE() AND ENGINE='InnoDB' AND TABLE_NAME IN "+names,rows)||db.warnings||rows.size()!=1||rows[0].size()!=1||rows[0][0]!="3")return -1;
|
||||
if(!db.Query("SELECT version FROM port_cube_gold_version WHERE id=1",rows)||db.warnings||rows.size()!=1||rows[0].size()!=1||rows[0][0]!="2")return -1;
|
||||
return 1;
|
||||
}
|
||||
struct GoldRecord {GoldIntent intent;bool applied=false;uint64_t before=0,after=0;};
|
||||
// Caller holds the account lock. No inferred deltas from a stale game snapshot.
|
||||
template<class DB> bool GoldRecords(DB& db,const Batch& b,std::vector<GoldRecord>& records) {
|
||||
records.clear();PortEconomy::Rows rows;
|
||||
if(!db.Query("SELECT event,seq,account,pid,body,state,before_gold,after_gold FROM port_cube_gold_intents WHERE request='"+b.token+"' ORDER BY seq FOR UPDATE",rows)||db.warnings||rows.size()>GoldIntentLimit)return false;
|
||||
bool pending=false;std::set<std::string> ids;uint64_t previous=0;
|
||||
for(const auto& row:rows) {
|
||||
GoldRecord record;if(row.size()!=8||!DecodeGoldIntent(row[4],record.intent)||!Matches(record.intent,b))return false;
|
||||
const auto& i=record.intent;
|
||||
if(i.sequence!=records.size()+1||row[0]!=i.event||row[1]!=std::to_string(i.sequence)||row[2]!=std::to_string(i.account)||row[3]!=std::to_string(i.player)||!ids.insert(i.event).second)return false;
|
||||
if(!PortEconomy::Number(row[6],record.before,PortEconomy::GoldLimit)||!PortEconomy::Number(row[7],record.after,PortEconomy::GoldLimit))return false;
|
||||
record.applied=row[5]=="APPLIED";
|
||||
if(record.applied) {
|
||||
if(pending||record.before>uint64_t(PortEconomy::GoldLimit)-i.amount||record.after!=record.before+i.amount||(!records.empty()&&record.before!=previous))return false;
|
||||
previous=record.after;
|
||||
} else {if(row[5]!="QUEUED"||record.before||record.after)return false;pending=true;}
|
||||
records.push_back(std::move(record));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
template<class DB> int GoldCreditBase(DB& db,const Batch& b,uint64_t& base) {
|
||||
PortEconomy::Rows rows;typename BatchStore<DB>::Receipt receipt;
|
||||
if(!db.Query("SELECT body,rolls,state,result,successes,fee,awards FROM port_cube_requests WHERE token='"+b.token+"' AND account="+std::to_string(b.account)+" AND pid="+std::to_string(b.player)+" FOR UPDATE",rows)||db.warnings)return -1;
|
||||
if(rows.size()!=1||!BatchStore<DB>::DoneReceipt(b,rows[0],receipt)||receipt.fee>b.gold)return 0;
|
||||
base=b.gold-receipt.fee;return 1;
|
||||
}
|
||||
template<class DB> int GoldIntentsStatus(DB& db,const Batch& b) {
|
||||
const int schema=GoldSchema(db);if(schema==0)return 1;if(schema<0)return -1;
|
||||
std::vector<GoldRecord> records;if(!GoldRecords(db,b,records))return -1;
|
||||
// Even zero credits need an explicit closed-source proof. SQL emptiness
|
||||
// cannot exclude a local durable intent whose delivery has not arrived.
|
||||
PortEconomy::Rows seals;
|
||||
if(!db.Query("SELECT account,pid,epoch,owner,session,cookie,handle,manifest FROM port_cube_gold_sources WHERE request='"+b.token+"' FOR UPDATE",seals)||db.warnings)return -1;
|
||||
if(seals.empty())return 0;
|
||||
if(seals.size()!=1||seals[0].size()!=8)return -1;
|
||||
const auto& row=seals[0];GoldSourceSeal seal;static_cast<GoldSourceBinding&>(seal)=GoldSourceFor(b,0,0,0);
|
||||
uint64_t cookie=0,handle=0;
|
||||
if(row[0]!=std::to_string(b.account)||row[1]!=std::to_string(b.player)||row[2]!=std::to_string(b.epoch)||row[3]!=b.owner||
|
||||
!PortEconomy::Number(row[4],seal.session)||!PortEconomy::Number(row[5],cookie,UINT32_MAX)||!PortEconomy::Number(row[6],handle,UINT32_MAX))return -1;
|
||||
seal.cookie=uint32_t(cookie);seal.handle=uint32_t(handle);
|
||||
if(EncodeGoldSourceBinding(seal).empty()||!DecodeGoldManifest(row[7],seal.events)||seal.events.size()!=records.size())return -1;
|
||||
for(size_t n=0;n<records.size();++n)if(records[n].intent.event!=seal.events[n])return -1;
|
||||
for(const auto& record:records)if(!record.applied)return 0;
|
||||
if(!records.empty()) {
|
||||
uint64_t base=0,current=0;PortEconomy::Rows rows;
|
||||
const int ready=GoldCreditBase(db,b,base);if(ready<0)return -1;if(!ready||records.front().before!=base)return 0;
|
||||
if(!db.Query("SELECT gold FROM player WHERE id="+std::to_string(b.player)+" AND account_id="+std::to_string(b.account)+" FOR UPDATE",rows)||db.warnings)return -1;
|
||||
if(rows.size()!=1||rows[0].size()!=1||!PortEconomy::Number(rows[0][0],current,PortEconomy::GoldLimit)||current!=records.back().after)return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
#pragma once
|
||||
#include "cube_gold_intent.h"
|
||||
#include <cerrno>
|
||||
#include <fcntl.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/stat.h>
|
||||
#include <tuple>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace PortCube {
|
||||
// Core-private, bounded append-only journal. ACK means DB has the immutable
|
||||
// intent, NOT that currency is applied or the actor may thaw. Keep ACK history
|
||||
// so a restarted writer cannot reuse a sequence. No automatic compaction yet.
|
||||
struct GoldDelivery {
|
||||
GoldIntent intent;
|
||||
uint64_t session=0;
|
||||
uint32_t cookie=0,handle=0,ground=0,vnum=0,map=0;
|
||||
};
|
||||
constexpr size_t GoldDeliveryBytes=GoldIntentBytes+28;
|
||||
inline std::string EncodeGoldDelivery(const GoldDelivery& d) {
|
||||
const auto body=EncodeGoldIntent(d.intent);
|
||||
if(body.empty()||d.intent.source!=1||!d.session||!d.cookie||!d.handle||!d.ground||!d.vnum||!d.map)return {};
|
||||
Writer w;w.data=body;w.n(d.session,8);w.n(d.cookie,4);w.n(d.handle,4);w.n(d.ground,4);w.n(d.vnum,4);w.n(d.map,4);return w.data;
|
||||
}
|
||||
inline bool DecodeGoldDelivery(const std::string& body,GoldDelivery& d) {
|
||||
d={};if(body.size()!=GoldDeliveryBytes)return false;GoldDelivery out;
|
||||
if(!DecodeGoldIntent(body.substr(0,GoldIntentBytes),out.intent))return false;
|
||||
Reader r(body);r.at=GoldIntentBytes;out.session=r.n(8);out.cookie=uint32_t(r.n(4));out.handle=uint32_t(r.n(4));
|
||||
out.ground=uint32_t(r.n(4));out.vnum=uint32_t(r.n(4));out.map=uint32_t(r.n(4));
|
||||
if(!r.ok||r.at!=body.size()||EncodeGoldDelivery(out)!=body)return false;d=std::move(out);return true;
|
||||
}
|
||||
inline GoldSourceBinding GoldSourceFor(const GoldDelivery& d) {
|
||||
GoldSourceBinding s;s.account=d.intent.account;s.player=d.intent.player;s.epoch=d.intent.epoch;s.owner=d.intent.owner;s.request=d.intent.request;
|
||||
s.session=d.session;s.cookie=d.cookie;s.handle=d.handle;return s;
|
||||
}
|
||||
class GoldOutbox {
|
||||
struct Record {GoldDelivery delivery;bool acknowledged=false;};
|
||||
struct Closing {GoldSourceBinding binding;unsigned count=0;bool acknowledged=false;};
|
||||
int fd=-1,lock=-1,directory=-1;bool healthy=false;size_t bytes=0;
|
||||
std::string error;std::map<std::string,Record> records;
|
||||
std::map<std::string,Closing> sources;
|
||||
static uint32_t Hash(const std::string& body){uint32_t h=2166136261u;for(unsigned char c:body){h^=c;h*=16777619u;}return h;}
|
||||
bool Fail(const char* reason){healthy=false;error=reason;return false;}
|
||||
static bool PrivateFile(int f){struct stat s={};return fstat(f,&s)==0&&S_ISREG(s.st_mode)&&s.st_nlink==1&&s.st_uid==geteuid()&&!(s.st_mode&0022);}
|
||||
static bool WriteAll(int f,const std::string& body) {
|
||||
size_t at=0;while(at<body.size()){const auto n=write(f,body.data()+at,body.size()-at);if(n<0&&errno==EINTR)continue;if(n<=0)return false;at+=size_t(n);}return true;
|
||||
}
|
||||
static std::string ClosingBody(const Closing& c) {
|
||||
const auto binding=EncodeGoldSourceBinding(c.binding);if(binding.empty()||c.count>GoldSourceLimit)return {};
|
||||
Writer w;w.data=binding;w.n(c.count,4);w.data.resize(GoldDeliveryBytes,'\0');return w.data;
|
||||
}
|
||||
static bool DecodeClosing(const std::string& body,Closing& c) {
|
||||
c={};if(body.size()!=GoldDeliveryBytes)return false;Closing out;
|
||||
if(!DecodeGoldSourceBinding(body.substr(0,GoldSourceBindingBytes),out.binding))return false;
|
||||
Reader r(body);r.at=GoldSourceBindingBytes;out.count=unsigned(r.n(4));if(!r.ok||ClosingBody(out)!=body)return false;c=std::move(out);return true;
|
||||
}
|
||||
bool SourceImage(const GoldSourceBinding& binding,bool requireAck,GoldSourceSeal& seal)const {
|
||||
seal={};if(EncodeGoldSourceBinding(binding).empty())return false;static_cast<GoldSourceBinding&>(seal)=binding;
|
||||
std::vector<std::pair<unsigned,std::string>> ordered;
|
||||
for(const auto& entry:records)if(entry.second.delivery.intent.request==binding.request) {
|
||||
const auto& r=entry.second;
|
||||
if((requireAck&&!r.acknowledged)||EncodeGoldSourceBinding(GoldSourceFor(r.delivery))!=EncodeGoldSourceBinding(binding))return false;
|
||||
ordered.emplace_back(r.delivery.intent.sequence,r.delivery.intent.event);
|
||||
}
|
||||
std::sort(ordered.begin(),ordered.end());for(const auto& e:ordered){if(e.first!=seal.events.size()+1)return false;seal.events.push_back(e.second);}
|
||||
return !EncodeGoldManifest(seal.events).empty();
|
||||
}
|
||||
bool AppendBody(unsigned op,const std::string& body) {
|
||||
Writer w;w.data="CGO1";w.n(op,1);w.data+=body;w.n(Hash(w.data),4);const auto& frame=w.data;
|
||||
if(!healthy||frame.size()!=FrameBytes||bytes>MaxBytes-frame.size())return Fail("gold outbox unavailable/full; retain hold and journal");
|
||||
if(!WriteAll(fd,frame)||fsync(fd)!=0)return Fail("gold outbox write/sync uncertain; quarantine source and retain journal");
|
||||
bytes+=frame.size();return true;
|
||||
}
|
||||
bool Append(unsigned op,const GoldDelivery& d){return AppendBody(op,EncodeGoldDelivery(d));}
|
||||
bool Admit(const GoldDelivery& d)const {
|
||||
if(EncodeGoldDelivery(d).empty()||records.size()>=MaxRecords||sources.count(d.intent.request))return false;
|
||||
unsigned sequence=1;
|
||||
for(const auto& entry:records)if(entry.second.delivery.intent.request==d.intent.request) {
|
||||
const auto& i=entry.second.delivery.intent;
|
||||
if(i.account!=d.intent.account||i.player!=d.intent.player||i.epoch!=d.intent.epoch||i.owner!=d.intent.owner)return false;
|
||||
if(EncodeGoldSourceBinding(GoldSourceFor(entry.second.delivery))!=EncodeGoldSourceBinding(GoldSourceFor(d)))return false;
|
||||
++sequence;
|
||||
}
|
||||
return d.intent.sequence==sequence;
|
||||
}
|
||||
public:
|
||||
static constexpr size_t MaxRecords=8192,MaxBytes=16*1024*1024,FrameBytes=4+1+GoldDeliveryBytes+4;
|
||||
GoldOutbox()=default;GoldOutbox(const GoldOutbox&)=delete;GoldOutbox& operator=(const GoldOutbox&)=delete;
|
||||
~GoldOutbox(){if(fd>=0)close(fd);if(lock>=0)close(lock);if(directory>=0)close(directory);}
|
||||
bool Ready()const{return healthy;}
|
||||
const std::string& Error()const{return error;}
|
||||
bool Open(const std::string& path) {
|
||||
if(fd>=0||lock>=0||directory>=0)return Fail("gold outbox already opened");
|
||||
const auto slash=path.rfind('/');const std::string dir=slash==std::string::npos?".":slash==0?"/":path.substr(0,slash);
|
||||
const std::string name=slash==std::string::npos?path:path.substr(slash+1);
|
||||
if(name.empty()||name=="."||name=="..")return Fail("invalid gold outbox path");
|
||||
if(mkdir(dir.c_str(),0700)!=0&&errno!=EEXIST)return Fail("cannot create gold outbox directory");
|
||||
directory=open(dir.c_str(),O_RDONLY|O_DIRECTORY|O_NOFOLLOW);
|
||||
if(directory<0)return Fail("cannot open gold outbox directory");
|
||||
lock=openat(directory,(name+".lock").c_str(),O_RDWR|O_CREAT|O_NOFOLLOW,0600);
|
||||
if(lock<0||!PrivateFile(lock)||flock(lock,LOCK_EX|LOCK_NB)!=0)return Fail("gold outbox already owned/unsafe lock");
|
||||
fd=openat(directory,name.c_str(),O_RDWR|O_CREAT|O_APPEND|O_NOFOLLOW,0600);
|
||||
if(fd<0||!PrivateFile(fd)||flock(fd,LOCK_EX|LOCK_NB)!=0)return Fail("unsafe/owned gold outbox file");
|
||||
struct stat info={};if(fstat(fd,&info)!=0||info.st_size<0||uint64_t(info.st_size)>MaxBytes)return Fail("gold outbox size invalid");
|
||||
bytes=size_t(info.st_size);
|
||||
if(fsync(fd)!=0||fsync(lock)!=0||fsync(directory)!=0)return Fail("cannot persist gold outbox directory entries");
|
||||
if(bytes%FrameBytes)return Fail("torn gold outbox; retain bytes for repair");
|
||||
for(size_t at=0;at<bytes;at+=FrameBytes) {
|
||||
std::string frame(FrameBytes,'\0');size_t got=0;
|
||||
while(got<frame.size()){const auto n=pread(fd,&frame[got],frame.size()-got,off_t(at+got));if(n<0&&errno==EINTR)continue;if(n<=0)return Fail("cannot read gold outbox");got+=size_t(n);}
|
||||
Reader checksum(frame);checksum.at=FrameBytes-4;
|
||||
if(frame.substr(0,4)!="CGO1"||checksum.n(4)!=Hash(frame.substr(0,FrameBytes-4)))return Fail("corrupt gold outbox; retain bytes for repair");
|
||||
const unsigned op=uint8_t(frame[4]);const auto body=frame.substr(5,GoldDeliveryBytes);
|
||||
if(op==3||op==4) {
|
||||
Closing c;GoldSourceSeal seal;
|
||||
if(!DecodeClosing(body,c)||!SourceImage(c.binding,op==4,seal)||seal.events.size()!=c.count)return Fail("corrupt source close proof");
|
||||
auto it=sources.find(c.binding.request);
|
||||
if(op==3) {
|
||||
if(it!=sources.end()||sources.size()>=MaxRecords)return Fail("duplicate/overfull source close");
|
||||
sources.emplace(c.binding.request,c);
|
||||
} else {
|
||||
if(it==sources.end()||it->second.acknowledged||ClosingBody(it->second)!=body)return Fail("unknown/conflicting source close ACK");
|
||||
it->second.acknowledged=true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
GoldDelivery d;if(!DecodeGoldDelivery(body,d))return Fail("corrupt gold delivery body");auto it=records.find(d.intent.event);
|
||||
if(op==1) {
|
||||
if(it!=records.end()||!Admit(d))return Fail("conflicting/out-of-order gold outbox claim");
|
||||
records.emplace(d.intent.event,Record{d,false});
|
||||
} else if(op==2) {
|
||||
if(it==records.end()||it->second.acknowledged||EncodeGoldDelivery(it->second.delivery)!=EncodeGoldDelivery(d))return Fail("unknown/conflicting gold outbox ACK");
|
||||
it->second.acknowledged=true;
|
||||
} else return Fail("unknown gold outbox operation");
|
||||
}
|
||||
healthy=true;return true;
|
||||
}
|
||||
unsigned Next(const std::string& request)const {unsigned n=1;for(const auto& r:records)if(r.second.delivery.intent.request==request)++n;return n;}
|
||||
uint64_t Total(const std::string& request)const {
|
||||
uint64_t total=0;for(const auto& r:records)if(r.second.delivery.intent.request==request) {
|
||||
if(total>uint64_t(PortEconomy::GoldLimit)-r.second.delivery.intent.amount)return uint64_t(PortEconomy::GoldLimit);
|
||||
total+=r.second.delivery.intent.amount;
|
||||
}return total;
|
||||
}
|
||||
const GoldDelivery* Find(const std::string& event)const {auto it=records.find(event);return it==records.end()?nullptr:&it->second.delivery;}
|
||||
bool Claim(const GoldDelivery& d) {
|
||||
if(!healthy||EncodeGoldDelivery(d).empty())return false;auto it=records.find(d.intent.event);
|
||||
if(it!=records.end())return EncodeGoldDelivery(it->second.delivery)==EncodeGoldDelivery(d);
|
||||
if(!Admit(d)){error="gold outbox capacity/sequence/identity refused before writing";return false;}
|
||||
if(!Append(1,d))return false;records.emplace(d.intent.event,Record{d,false});return true;
|
||||
}
|
||||
bool Acknowledge(const GoldDelivery& d) {
|
||||
auto it=records.find(d.intent.event);
|
||||
if(!healthy||it==records.end()||EncodeGoldDelivery(it->second.delivery)!=EncodeGoldDelivery(d))return false;
|
||||
if(it->second.acknowledged)return true;
|
||||
if(!Append(2,d))return false;it->second.acknowledged=true;return true;
|
||||
}
|
||||
bool IsClosing(const std::string& request)const{return sources.count(request)!=0;}
|
||||
bool CloseSource(const GoldSourceBinding& binding) {
|
||||
if(!healthy)return false;GoldSourceSeal seal;if(!SourceImage(binding,false,seal))return false;
|
||||
auto it=sources.find(binding.request);Closing c{binding,unsigned(seal.events.size()),false};
|
||||
if(it!=sources.end())return ClosingBody(it->second)==ClosingBody(c);
|
||||
if(sources.size()>=MaxRecords)return false;
|
||||
// Stop new claims DURABLY before waiting for existing delivery ACKs.
|
||||
if(!AppendBody(3,ClosingBody(c)))return false;sources.emplace(binding.request,std::move(c));return true;
|
||||
}
|
||||
bool AcknowledgeSource(const GoldSourceSeal& seal) {
|
||||
if(!healthy)return false;auto it=sources.find(seal.request);GoldSourceSeal expected;
|
||||
if(it==sources.end()||EncodeGoldSourceBinding(seal)!=EncodeGoldSourceBinding(it->second.binding)||!SourceImage(seal,true,expected)||
|
||||
seal.events!=expected.events||seal.events.size()!=it->second.count)return false;
|
||||
if(it->second.acknowledged)return true;
|
||||
if(!AppendBody(4,ClosingBody(it->second)))return false;it->second.acknowledged=true;return true;
|
||||
}
|
||||
bool SourceAcknowledged(const GoldSourceBinding& binding)const {
|
||||
auto it=sources.find(binding.request);return healthy&&it!=sources.end()&&it->second.acknowledged&&EncodeGoldSourceBinding(binding)==EncodeGoldSourceBinding(it->second.binding);
|
||||
}
|
||||
std::vector<GoldSourceSeal> PendingSources()const {
|
||||
std::vector<GoldSourceSeal> out;if(!healthy)return out;
|
||||
for(const auto& entry:sources)if(!entry.second.acknowledged) {
|
||||
GoldSourceSeal seal;if(SourceImage(entry.second.binding,true,seal)&&seal.events.size()==entry.second.count)out.push_back(std::move(seal));
|
||||
}return out;
|
||||
}
|
||||
std::vector<GoldDelivery> Pending()const {
|
||||
std::vector<GoldDelivery> out;if(!healthy)return out;
|
||||
for(const auto& r:records)if(!r.second.acknowledged)out.push_back(r.second.delivery);
|
||||
std::sort(out.begin(),out.end(),[](const auto& a,const auto& b){return std::tie(a.intent.account,a.intent.player,a.intent.request,a.intent.sequence)<std::tie(b.intent.account,b.intent.player,b.intent.request,b.intent.sequence);});return out;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
#include "cube_batch.h"
|
||||
namespace PortCube {
|
||||
constexpr unsigned GoldSourceLimit=1024,GoldSourceBindingBytes=96;
|
||||
struct GoldSourceBinding {
|
||||
uint32_t account=0,player=0,cookie=0,handle=0;
|
||||
uint64_t epoch=0,session=0;
|
||||
std::string owner,request;
|
||||
};
|
||||
struct GoldSourceSeal : GoldSourceBinding {std::vector<std::string> events;};
|
||||
inline std::string EncodeGoldSourceBinding(const GoldSourceBinding& s) {
|
||||
if(!s.account||!s.player||!s.epoch||!s.session||!s.cookie||!s.handle||!Identity(s.owner)||!Identity(s.request))return {};
|
||||
Writer w;w.n(s.account,4);w.n(s.player,4);w.n(s.epoch,8);w.data+=s.owner;w.data+=s.request;w.n(s.session,8);w.n(s.cookie,4);w.n(s.handle,4);return w.data;
|
||||
}
|
||||
inline bool DecodeGoldSourceBinding(const std::string& body,GoldSourceBinding& s) {
|
||||
s={};if(body.size()!=GoldSourceBindingBytes)return false;Reader r(body);GoldSourceBinding out;
|
||||
out.account=uint32_t(r.n(4));out.player=uint32_t(r.n(4));out.epoch=r.n(8);out.owner=body.substr(r.at,32);out.request=body.substr(r.at+32,32);r.at+=64;
|
||||
out.session=r.n(8);out.cookie=uint32_t(r.n(4));out.handle=uint32_t(r.n(4));
|
||||
if(!r.ok||r.at!=body.size()||EncodeGoldSourceBinding(out)!=body)return false;s=std::move(out);return true;
|
||||
}
|
||||
inline bool Matches(const GoldSourceBinding& s,const Batch& b) {
|
||||
return s.account==b.account&&s.player==b.player&&s.epoch==b.epoch&&s.owner==b.owner&&s.request==b.token;
|
||||
}
|
||||
inline std::string EncodeGoldManifest(const std::vector<std::string>& events) {
|
||||
if(events.size()>GoldSourceLimit)return {};std::set<std::string> seen;Writer w;w.n(events.size(),4);
|
||||
for(const auto& e:events){if(!Identity(e)||!seen.insert(e).second)return {};w.data+=e;}return w.data;
|
||||
}
|
||||
inline bool DecodeGoldManifest(const std::string& body,std::vector<std::string>& events) {
|
||||
events.clear();if(body.size()<4||body.size()>4+32*GoldSourceLimit)return false;Reader r(body);const auto count=r.n(4);
|
||||
if(count>GoldSourceLimit||body.size()!=4+32*count)return false;
|
||||
std::vector<std::string> out;for(size_t n=0;n<count;++n)out.push_back(body.substr(4+n*32,32));
|
||||
if(EncodeGoldManifest(out)!=body)return false;events=std::move(out);return true;
|
||||
}
|
||||
inline GoldSourceBinding GoldSourceFor(const Batch& b,uint64_t session,uint32_t cookie,uint32_t handle) {
|
||||
GoldSourceBinding s;s.account=b.account;s.player=b.player;s.epoch=b.epoch;s.owner=b.owner;s.request=b.token;s.session=session;s.cookie=cookie;s.handle=handle;return s;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
#pragma once
|
||||
#include "cube_gold_intent.h"
|
||||
namespace PortCube {
|
||||
// Candidate deferred positive-credit backend; actual ingress remains disabled.
|
||||
// Sources must durably identify an event BEFORE acknowledging delivery;
|
||||
// do not divert an already-performed PointChange here or double-credit memory.
|
||||
template<class DB> class GoldIntentStore {
|
||||
DB& db;Lookup lookup;using Rows=PortEconomy::Rows;
|
||||
static std::string N(uint64_t n){return std::to_string(n);}
|
||||
bool Q(const std::string& sql,Rows& rows){return db.Query(sql,rows)&&!db.warnings;}
|
||||
bool Run(const std::string& sql){Rows rows;return Q(sql,rows);}
|
||||
bool Change(const std::string& sql){return Run(sql)&&db.affected==1;}
|
||||
struct Guard {DB& db;~Guard(){db.Rollback();}};
|
||||
bool Account(uint32_t account) {
|
||||
Rows rows;return Run("INSERT INTO port_economy_account_lock(account) VALUES("+N(account)+") ON DUPLICATE KEY UPDATE account=VALUES(account)")&&
|
||||
Q("SELECT account FROM port_economy_account_lock WHERE account="+N(account)+" FOR UPDATE",rows)&&rows.size()==1;
|
||||
}
|
||||
bool Fence(uint32_t account,uint32_t player,Rows& rows) {
|
||||
return Q("SELECT account,epoch,owner,request,phase,body,drain_state FROM port_cube_fences WHERE pid="+N(player)+" AND account="+N(account)+" FOR UPDATE",rows);
|
||||
}
|
||||
static bool Same(const Batch& b,const Rows& rows) {
|
||||
return rows.size()==1&&rows[0].size()==7&&rows[0][0]==N(b.account)&&rows[0][1]==N(b.epoch)&&rows[0][2]==b.owner&&rows[0][3]==b.token&&rows[0][5]==Encode(b);
|
||||
}
|
||||
public:
|
||||
enum Result {Retry,Refused,Stored,Applied,Blocked};
|
||||
struct Receipt {uint64_t before=0,after=0;};
|
||||
GoldIntentStore(DB& database,Lookup proto):db(database),lookup(std::move(proto)){}
|
||||
bool Ready(){BatchStore<DB> base(db,lookup);return base.Ready()&&GoldSchema(db)==1;}
|
||||
Result Enqueue(const Batch& b,const GoldIntent& i) {
|
||||
if(!Validate(b)||!ValidGoldIntent(i)||!Matches(i,b))return Refused;
|
||||
if(!Ready()||!db.Begin())return Retry;Guard guard{db};Rows rows;
|
||||
if(!Account(b.account))return Retry;
|
||||
const auto body=EncodeGoldIntent(i);
|
||||
if(!Q("SELECT body,state,before_gold,after_gold FROM port_cube_gold_intents WHERE event='"+i.event+"' FOR UPDATE",rows))return Retry;
|
||||
if(!rows.empty()) {
|
||||
if(rows.size()!=1||rows[0].size()!=4||rows[0][0]!=body)return Refused;
|
||||
uint64_t before=0,after=0;
|
||||
if(!PortEconomy::Number(rows[0][2],before,PortEconomy::GoldLimit)||!PortEconomy::Number(rows[0][3],after,PortEconomy::GoldLimit))return Blocked;
|
||||
if(rows[0][1]=="QUEUED")return !before&&!after?Stored:Blocked;
|
||||
return rows[0][1]=="APPLIED"&&before<=uint64_t(PortEconomy::GoldLimit)-i.amount&&after==before+i.amount?Applied:Blocked;
|
||||
}
|
||||
if(!Fence(b.account,b.player,rows))return Retry;
|
||||
if(!Same(b,rows))return Blocked;
|
||||
const auto phase=rows[0][4];
|
||||
if(phase!="DRAINING"&&phase!="FROZEN"&&phase!="ABORTED")return Blocked;
|
||||
if(!Q("SELECT request FROM port_cube_gold_sources WHERE request='"+b.token+"' FOR UPDATE",rows))return Retry;
|
||||
if(!rows.empty())return Blocked; // exact historical event replay above is still allowed
|
||||
std::vector<GoldRecord> records;if(!GoldRecords(db,b,records))return Blocked;
|
||||
if(i.sequence!=records.size()+1)return Refused;
|
||||
if(!Change("INSERT INTO port_cube_gold_intents(event,request,seq,account,pid,body,state,before_gold,after_gold) VALUES('"+i.event+"','"+i.request+"',"+N(i.sequence)+","+N(i.account)+","+N(i.player)+",X'"+PortEconomy::Hex(body.data(),body.size())+"','QUEUED',0,0)"))return Retry;
|
||||
return db.Commit()?Stored:Retry;
|
||||
}
|
||||
Result CloseSource(const Batch& b,const GoldSourceSeal& seal) {
|
||||
const auto manifest=EncodeGoldManifest(seal.events);
|
||||
if(!Validate(b)||!Matches(seal,b)||EncodeGoldSourceBinding(seal).empty()||manifest.empty())return Refused;
|
||||
if(!Ready()||!db.Begin())return Retry;Guard guard{db};Rows rows;
|
||||
if(!Account(b.account))return Retry;
|
||||
const std::vector<std::string> expected={N(b.account),N(b.player),N(b.epoch),b.owner,N(seal.session),N(seal.cookie),N(seal.handle),manifest};
|
||||
if(!Q("SELECT account,pid,epoch,owner,session,cookie,handle,manifest FROM port_cube_gold_sources WHERE request='"+b.token+"' FOR UPDATE",rows))return Retry;
|
||||
if(!rows.empty())return rows.size()==1&&rows[0]==expected?Stored:Refused;
|
||||
if(!Fence(b.account,b.player,rows))return Retry;
|
||||
if(!Same(b,rows)||!((rows[0][4]=="FROZEN"&&rows[0][6]=="1")||(rows[0][4]=="ABORTED"&&rows[0][6]=="2")))return Blocked;
|
||||
std::vector<GoldRecord> records;if(!GoldRecords(db,b,records))return Blocked;
|
||||
if(records.size()!=seal.events.size())return Blocked;
|
||||
for(size_t n=0;n<records.size();++n)if(records[n].intent.event!=seal.events[n])return Refused;
|
||||
if(!Change("INSERT INTO port_cube_gold_sources(request,account,pid,epoch,owner,session,cookie,handle,manifest) VALUES('"+b.token+"',"+N(b.account)+","+N(b.player)+","+N(b.epoch)+",'"+b.owner+"',"+N(seal.session)+","+N(seal.cookie)+","+N(seal.handle)+",X'"+PortEconomy::Hex(manifest.data(),manifest.size())+"')"))return Retry;
|
||||
return db.Commit()?Stored:Retry;
|
||||
}
|
||||
// Recover accepted intents after process restart without caller-supplied
|
||||
// amounts or replacing persisted data. Pure read: does not credit anything.
|
||||
Result Pending(const Batch& b,std::vector<GoldIntent>& pending) {
|
||||
pending.clear();if(!Validate(b))return Refused;
|
||||
if(!Ready()||!db.Begin())return Retry;Guard guard{db};
|
||||
if(!Account(b.account))return Retry;
|
||||
std::vector<GoldRecord> records;if(!GoldRecords(db,b,records))return Blocked;
|
||||
for(const auto& record:records)if(!record.applied)pending.push_back(record.intent);
|
||||
return Stored;
|
||||
}
|
||||
// Only identity comes from recovery. The persisted event/body and the DONE
|
||||
// Cube receipt determine the amount and expected base. Never auto-settle a
|
||||
// PREPARED craft, overwrite a stale wallet or apply on an aborted drain.
|
||||
Result Apply(const std::string& event,uint32_t account,uint32_t player,Receipt& receipt,
|
||||
const std::function<bool(const GoldIntent&)>& authorize={}) {
|
||||
receipt={};if(!Identity(event)||!account||!player)return Refused;
|
||||
if(!Ready()||!db.Begin())return Retry;Guard guard{db};Rows rows;
|
||||
if(!Account(account)||!Q("SELECT body,state,before_gold,after_gold FROM port_cube_gold_intents WHERE event='"+event+"' AND account="+N(account)+" AND pid="+N(player)+" FOR UPDATE",rows))return Retry;
|
||||
if(rows.empty())return Refused;
|
||||
GoldIntent intent;
|
||||
if(rows.size()!=1||rows[0].size()!=4||!DecodeGoldIntent(rows[0][0],intent)||intent.event!=event||intent.account!=account||intent.player!=player)return Blocked;
|
||||
if(authorize&&!authorize(intent))return Blocked; // same account transaction/pinned connection, including historical replay
|
||||
const auto saved=rows[0];uint64_t before=0,after=0;
|
||||
if(!PortEconomy::Number(saved[2],before,PortEconomy::GoldLimit)||!PortEconomy::Number(saved[3],after,PortEconomy::GoldLimit))return Blocked;
|
||||
if(saved[1]=="APPLIED") {
|
||||
if(before>uint64_t(PortEconomy::GoldLimit)-intent.amount||after!=before+intent.amount)return Blocked;
|
||||
receipt={before,after};return Applied; // historical replay, even after newer epochs
|
||||
}
|
||||
if(saved[1]!="QUEUED"||before||after)return Blocked;
|
||||
if(!Fence(account,player,rows))return Retry;
|
||||
Batch b;if(rows.size()!=1||rows[0].size()!=7||!Decode(rows[0][5],b)||!Same(b,rows)||!Matches(intent,b)||rows[0][4]!="FROZEN"||rows[0][6]!="1")return Blocked;
|
||||
std::vector<GoldRecord> records;if(!GoldRecords(db,b,records))return Blocked;
|
||||
uint64_t expected=0;const int base=GoldCreditBase(db,b,expected);if(base<0)return Retry;if(!base)return Blocked;
|
||||
unsigned next=1;
|
||||
for(const auto& record:records) {
|
||||
if(!record.applied)break;
|
||||
if(record.before!=expected)return Blocked;expected=record.after;++next;
|
||||
}
|
||||
if(intent.sequence!=next||next>records.size()||records[next-1].intent.event!=event)return Blocked;
|
||||
if(expected>uint64_t(PortEconomy::GoldLimit)-intent.amount)return Blocked;
|
||||
if(!Q("SELECT gold FROM player WHERE id="+N(player)+" AND account_id="+N(account)+" FOR UPDATE",rows))return Retry;
|
||||
uint64_t current=0;if(rows.size()!=1||rows[0].size()!=1||!PortEconomy::Number(rows[0][0],current,PortEconomy::GoldLimit)||current!=expected)return Blocked;
|
||||
const auto target=expected+intent.amount;
|
||||
if(!Change("UPDATE player SET gold=gold+"+N(intent.amount)+" WHERE id="+N(player)+" AND account_id="+N(account)+" AND gold="+N(expected))||
|
||||
!Change("UPDATE port_cube_gold_intents SET state='APPLIED',before_gold="+N(expected)+",after_gold="+N(target)+" WHERE event='"+event+"' AND state='QUEUED'")||!db.Commit())return Retry;
|
||||
receipt={expected,target};return Applied;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
#pragma once
|
||||
#include "cube_batch.h"
|
||||
#include "cube_mutation.h"
|
||||
#include "cube_gold_intent.h"
|
||||
#include "cube_owner_types.h"
|
||||
#include "cube_image.h"
|
||||
#include "cube_receipt.h"
|
||||
|
||||
namespace PortCube {
|
||||
// Internal game/DB only. Neither this header nor the catalogue advertises a
|
||||
// crafting capability. Keep BOTH gates closed until the mutation audit and the
|
||||
// settlement/resync/thaw path are complete. There is no command to toggle them.
|
||||
constexpr uint8_t HandshakeHeader=78;
|
||||
constexpr bool HandshakeEnabled=false,ActorMutationAuditComplete=false;
|
||||
enum class Message : uint8_t { Arm=1,Submit=2,Poll=3,Cancel=4,Answer=5,Invalidate=6,GoldEnqueue=7,GoldAck=8,GoldClose=9,GoldCloseAck=10,RecoveryClaim=11,RecoveryAnswer=12,RecoveryImageRequest=13,RecoveryImageAnswer=14,Prepare=15,Execute=16,CraftAnswer=17,LiveImageRequest=18,LiveImageAnswer=19,LiveImageAck=20,LiveImageAckAnswer=21,LiveReleaseRequest=22,LiveReleaseAnswer=23,LiveResumeCheckRequest=24,LiveResumeCheckAnswer=25 };
|
||||
enum class Status : uint8_t { None=0,Denied=1,Armed=2,Draining=3,Frozen=4,Aborted=5,Held=6,Cancelled=7,GoldStored=8,GoldApplied=9,GoldClosed=10,RecoveryGranted=11,RecoveryClear=12,RecoveryImageReady=13,Prepared=14,Complete=15,LiveImageReady=16,LiveImageAcknowledged=17,LiveReleased=18,LiveResumeChecked=19 };
|
||||
struct Handshake {
|
||||
Message message=Message::Arm;Status status=Status::None;
|
||||
uint32_t account=0,player=0,cookie=0;
|
||||
uint64_t session=0,epoch=0;
|
||||
std::string owner,token,body;
|
||||
};
|
||||
constexpr unsigned HandshakeFixed=102,HandshakeMaximum=HandshakeFixed+40000;
|
||||
inline bool SameIdentity(const Handshake& a,const Handshake& b) {
|
||||
return a.account==b.account&&a.player==b.player&&a.session==b.session&&a.epoch==b.epoch&&a.owner==b.owner&&a.token==b.token;
|
||||
}
|
||||
inline bool ValidHandshake(const Handshake& f) {
|
||||
if(f.message==Message::RecoveryImageRequest||f.message==Message::RecoveryImageAnswer) {
|
||||
OwnerGrant g;std::string image;
|
||||
if(f.message==Message::RecoveryImageAnswer&&f.status==Status::RecoveryImageReady){if(!DecodeRecoveryImage(f.body,g,image))return false;}
|
||||
else if(!DecodeOwnerGrant(f.body,g)||!(f.message==Message::RecoveryImageRequest?f.status==Status::None:f.status==Status::Held))return false;
|
||||
const auto& b=g.binding;return b.account==f.account&&b.player==f.player&&b.session==f.session&&b.cookie==f.cookie&&b.epoch==f.epoch&&b.owner==f.owner&&b.request==f.token;
|
||||
}
|
||||
if(f.message==Message::RecoveryClaim||f.message==Message::RecoveryAnswer) {
|
||||
if(!f.account||!f.player||!f.session)return false;
|
||||
if(f.message==Message::RecoveryAnswer&&f.status==Status::RecoveryGranted) {
|
||||
OwnerGrant g;return DecodeOwnerGrant(f.body,g)&&g.binding.account==f.account&&g.binding.player==f.player&&g.binding.session==f.session&&g.binding.epoch==f.epoch&&g.binding.owner==f.owner&&g.binding.request==f.token&&g.binding.cookie==f.cookie;
|
||||
}
|
||||
return !f.epoch&&!f.cookie&&f.owner==std::string(32,'0')&&f.token==std::string(32,'0')&&f.body.empty()&&
|
||||
(f.message==Message::RecoveryClaim?f.status==Status::None:(f.status==Status::Held||f.status==Status::RecoveryClear));
|
||||
}
|
||||
if(!f.account||!f.player||!f.session||!f.epoch||!Identity(f.owner)||!Identity(f.token)||f.body.size()>40000)return false;
|
||||
if(f.message==Message::LiveResumeCheckRequest||f.message==Message::LiveResumeCheckAnswer) {
|
||||
InventoryImage image;if(!f.cookie)return false;
|
||||
if(f.message==Message::LiveResumeCheckAnswer&&f.status==Status::Held)return f.body.empty();
|
||||
return f.status==(f.message==Message::LiveResumeCheckRequest?Status::None:Status::LiveResumeChecked)&&DecodeInventoryImage(f.body,image);
|
||||
}
|
||||
if(f.message==Message::LiveReleaseRequest||f.message==Message::LiveReleaseAnswer) {
|
||||
InventoryImage image;if(!f.cookie)return false;
|
||||
if(f.message==Message::LiveReleaseAnswer&&f.status==Status::Held)return f.body.empty();
|
||||
return f.status==(f.message==Message::LiveReleaseRequest?Status::None:Status::LiveReleased)&&DecodeInventoryImage(f.body,image);
|
||||
}
|
||||
if(f.message==Message::LiveImageAck||f.message==Message::LiveImageAckAnswer) {
|
||||
InventoryImage image;if(!f.cookie)return false;
|
||||
if(f.message==Message::LiveImageAckAnswer&&f.status==Status::Held)return f.body.empty();
|
||||
return f.status==(f.message==Message::LiveImageAck?Status::None:Status::LiveImageAcknowledged)&&DecodeInventoryImage(f.body,image);
|
||||
}
|
||||
if(f.message==Message::LiveImageRequest)return f.status==Status::None&&f.cookie&&f.body.empty();
|
||||
if(f.message==Message::LiveImageAnswer){InventoryImage image;return f.cookie&&(f.status==Status::Held?f.body.empty():f.status==Status::LiveImageReady&&DecodeInventoryImage(f.body,image));}
|
||||
if(f.message==Message::Prepare||f.message==Message::Execute)return f.status==Status::None&&f.cookie&&f.body.empty();
|
||||
if(f.message==Message::CraftAnswer) {
|
||||
if(!f.cookie)return false;if(f.status==Status::Held||f.status==Status::Prepared)return f.body.empty();
|
||||
CraftReceipt receipt;return f.status==Status::Complete&&DecodeCraftReceipt(f.body,receipt);
|
||||
}
|
||||
if(f.message==Message::GoldClose||f.message==Message::GoldCloseAck) {
|
||||
std::vector<std::string> events;if(!f.cookie||!DecodeGoldManifest(f.body,events))return false;
|
||||
return f.message==Message::GoldClose?f.status==Status::None:f.status==Status::GoldClosed;
|
||||
}
|
||||
if(f.message==Message::GoldEnqueue||f.message==Message::GoldAck) {
|
||||
GoldIntent i;if(!f.cookie||!DecodeGoldIntent(f.body,i)||i.source!=1||i.account!=f.account||i.player!=f.player||i.epoch!=f.epoch||i.owner!=f.owner||i.request!=f.token)return false;
|
||||
return f.message==Message::GoldEnqueue?f.status==Status::None:(f.status==Status::GoldStored||f.status==Status::GoldApplied);
|
||||
}
|
||||
if(f.message==Message::Answer) {
|
||||
if(!f.body.empty()||f.status<Status::Denied||f.status>Status::Cancelled)return false;
|
||||
return (f.status!=Status::Armed&&f.status!=Status::Draining&&f.status!=Status::Frozen&&f.status!=Status::Aborted)||f.cookie;
|
||||
}
|
||||
if(f.status!=Status::None)return false;
|
||||
if(f.message==Message::Arm) {
|
||||
Batch b;if(f.cookie||!Decode(f.body,b))return false;
|
||||
return b.account==f.account&&b.player==f.player&&b.epoch==f.epoch&&b.owner==f.owner&&b.token==f.token;
|
||||
}
|
||||
return (f.message==Message::Submit||f.message==Message::Poll||f.message==Message::Cancel||f.message==Message::Invalidate)&&f.cookie&&f.body.empty();
|
||||
}
|
||||
inline bool IsDbHandshakeReply(Message m){return m==Message::Answer||m==Message::GoldAck||m==Message::GoldCloseAck||m==Message::RecoveryAnswer||m==Message::RecoveryImageAnswer||m==Message::CraftAnswer||m==Message::LiveImageAnswer||m==Message::LiveImageAckAnswer||m==Message::LiveReleaseAnswer||m==Message::LiveResumeCheckAnswer;}
|
||||
inline std::string EncodeHandshake(const Handshake& f) {
|
||||
if(!ValidHandshake(f))return {};
|
||||
Writer w;w.n(HandshakeFixed+f.body.size(),4);w.n(1,1);w.n(unsigned(f.message),1);w.n(unsigned(f.status),1);w.n(0,1);
|
||||
w.n(f.account,4);w.n(f.player,4);w.n(f.cookie,4);w.n(f.session,8);w.n(f.epoch,8);
|
||||
w.data+=f.owner;w.data+=f.token;w.n(f.body.size(),2);w.data+=f.body;return w.data;
|
||||
}
|
||||
// Safe before dereferencing any frame payload, including DB's unaligned 9-byte
|
||||
// outer packet prefix. No struct cast, native long, padding or host byte order.
|
||||
inline bool DecodeHandshake(const char* data,size_t length,Handshake& f) {
|
||||
f={};if(!data||length<HandshakeFixed||length>HandshakeMaximum)return false;
|
||||
const std::string bytes(data,length);Reader r(bytes);
|
||||
if(r.n(4)!=length||r.n(1)!=1)return false;
|
||||
Handshake out;out.message=Message(r.n(1));out.status=Status(r.n(1));if(r.n(1)!=0)return false;
|
||||
out.account=uint32_t(r.n(4));out.player=uint32_t(r.n(4));out.cookie=uint32_t(r.n(4));out.session=r.n(8);out.epoch=r.n(8);
|
||||
if(!r.ok||r.at+64>bytes.size())return false;
|
||||
out.owner=bytes.substr(r.at,32);out.token=bytes.substr(r.at+32,32);r.at+=64;
|
||||
out.body=r.s(40000);
|
||||
if(!r.ok||r.at!=bytes.size()||!ValidHandshake(out))return false;f=std::move(out);return true;
|
||||
}
|
||||
inline Handshake ArmFrame(const Batch& b,uint64_t session) {
|
||||
Handshake f;f.account=b.account;f.player=b.player;f.session=session;f.epoch=b.epoch;f.owner=b.owner;f.token=b.token;f.body=Encode(b);return f;
|
||||
}
|
||||
|
||||
// Transport-independent preparation state machine. This does NOT pause events
|
||||
// or mutate assets. The game adapter must retain a real freeze throughout every
|
||||
// non-Idle state. No timeout or negative/unknown reply is permission to thaw.
|
||||
class ActorHandshake {
|
||||
public:
|
||||
enum Stage { Idle,WaitArm,WaitDrain,Held,WaitCancel };
|
||||
private:
|
||||
Stage stage=Idle;Handshake arm;uint64_t deadline=0;bool submitted=false;uint32_t mutations=0;
|
||||
public:
|
||||
Stage State()const{return stage;}
|
||||
bool BlocksActions()const{return stage!=Idle;}
|
||||
bool Submitted()const{return submitted;}
|
||||
uint32_t Invalidated()const{return mutations;}
|
||||
void Invalidate(uint32_t reason) {
|
||||
if(stage==Idle||!reason)return;
|
||||
mutations|=reason;
|
||||
// Before cookie arrival keep accepting that Arm ACK only to cancel it.
|
||||
// After Submit, nothing can pretend this was a never-submitted batch.
|
||||
if(submitted)stage=Held;
|
||||
}
|
||||
const Handshake& IdentityFrame()const{return arm;}
|
||||
bool Start(const Batch& b,uint64_t session,uint64_t now,bool auditedFreeze) {
|
||||
if(stage!=Idle||!auditedFreeze)return false;
|
||||
auto f=ArmFrame(b,session);if(!ValidHandshake(f))return false;
|
||||
arm=std::move(f);stage=WaitArm;deadline=now;submitted=false;mutations=0;return true;
|
||||
}
|
||||
Handshake Request(Message message)const {
|
||||
Handshake f=arm;f.body.clear();f.message=message;f.status=Status::None;return f;
|
||||
}
|
||||
bool Armed(const Handshake& answer,uint64_t now) {
|
||||
if(stage!=WaitArm||!ValidHandshake(answer)||answer.message!=Message::Answer||answer.status!=Status::Armed||!SameIdentity(arm,answer)||(arm.cookie&&arm.cookie!=answer.cookie))return false;
|
||||
arm.cookie=answer.cookie;deadline=now;return true;
|
||||
}
|
||||
bool Submit(bool snapshotUnchanged,uint64_t now) {
|
||||
if(stage!=WaitArm||!arm.cookie||!snapshotUnchanged||mutations)return false;
|
||||
// Mark BEFORE enqueue: a lost/disconnected send cannot be cancelled or
|
||||
// timed out as if the DB could not have seen it.
|
||||
submitted=true;stage=WaitDrain;deadline=now;return true;
|
||||
}
|
||||
bool Cancel() {
|
||||
if(stage!=WaitArm||!arm.cookie||submitted)return false;stage=WaitCancel;return true;
|
||||
}
|
||||
bool Answer(const Handshake& answer) {
|
||||
if(stage==Idle||!ValidHandshake(answer)||answer.message!=Message::Answer||!SameIdentity(arm,answer)||answer.cookie!=arm.cookie||!arm.cookie)return false;
|
||||
if(stage==WaitCancel&&answer.status==Status::Cancelled&&!submitted){stage=Idle;arm={};return true;}
|
||||
if(answer.status==Status::Held||answer.status==Status::Aborted||answer.status==Status::Frozen){stage=Held;return true;}
|
||||
return false; // Denied/unknown/late Armed never authorize thaw
|
||||
}
|
||||
bool TimedOut(uint64_t now,uint64_t interval=10) {
|
||||
if(stage==Idle||now<deadline||now-deadline<interval)return false;
|
||||
stage=Held;return true;
|
||||
}
|
||||
void LostTransport(){if(stage!=Idle)stage=Held;}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include "cube_owner_types.h"
|
||||
namespace PortCube {
|
||||
// Existing fence image: gold8 + count2 + at most225*(reward114+cell2+usable1).
|
||||
constexpr unsigned InventoryImageMaximum=26335,RecoveryImageMaximum=OwnerGrantBytes+2+InventoryImageMaximum;
|
||||
struct InventoryImage {uint64_t gold=0;std::vector<Item> items;};
|
||||
inline std::string EncodeInventoryImage(const InventoryImage& i){Writer w;w.n(i.gold,8);w.items(i.items);return w.data;}
|
||||
inline bool DecodeInventoryImage(const std::string& bytes,InventoryImage& out,const Lookup& lookup={}) {
|
||||
out={};if(bytes.size()<10||bytes.size()>InventoryImageMaximum)return false;
|
||||
Reader r(bytes);InventoryImage image;image.gold=r.n(8);image.items=r.items();
|
||||
if(!r.ok||r.at!=bytes.size()||image.gold>uint64_t(PortEconomy::GoldLimit))return false;
|
||||
int last=-1;std::set<uint32_t> ids;std::array<bool,225> used={};
|
||||
for(const auto& item:image.items) {
|
||||
const auto& v=item.value;
|
||||
if(!v.id||!v.vnum||!v.count||v.count>2000||!item.usable||item.cell>=225||int(item.cell)<=last||!ids.insert(v.id).second)return false;last=item.cell;
|
||||
if(lookup) {
|
||||
const auto p=lookup(v.vnum);
|
||||
if(p.size<1||p.size>3||(!p.stackable&&v.count!=1)||(item.cell%45)/5+p.size>9)return false;
|
||||
for(unsigned n=0;n<p.size;++n){const auto at=item.cell+5*n;if(at>=225||used[at])return false;used[at]=true;}
|
||||
}
|
||||
}
|
||||
if(EncodeInventoryImage(image)!=bytes)return false;out=std::move(image);return true;
|
||||
}
|
||||
inline std::string EncodeRecoveryImage(const OwnerGrant& grant,const std::string& image) {
|
||||
InventoryImage decoded;const auto body=EncodeOwnerGrant(grant);
|
||||
if(body.empty()||!DecodeInventoryImage(image,decoded))return {};Writer w;w.data=body;w.s(image);return w.data;
|
||||
}
|
||||
inline bool DecodeRecoveryImage(const std::string& bytes,OwnerGrant& grant,std::string& image) {
|
||||
grant={};image.clear();if(bytes.size()<OwnerGrantBytes+12||bytes.size()>RecoveryImageMaximum)return false;
|
||||
OwnerGrant g;if(!DecodeOwnerGrant(bytes.substr(0,OwnerGrantBytes),g))return false;
|
||||
Reader r(bytes);r.at=OwnerGrantBytes;auto data=r.s(InventoryImageMaximum);InventoryImage decoded;
|
||||
if(!r.ok||r.at!=bytes.size()||!DecodeInventoryImage(data,decoded))return false;
|
||||
grant=std::move(g);image=std::move(data);return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
#include "cube_fence.h"
|
||||
#include "cube_owner.h"
|
||||
namespace PortCube {
|
||||
// Optional additive schema. An ACK records an exact applied image; it does not
|
||||
// release a lease, an item fence, or an actor. Never install tables at startup.
|
||||
template<class DB> bool ImageAckSchema(DB& db) {
|
||||
PortEconomy::Rows rows;
|
||||
const std::string names="('port_cube_image_ack_version','port_cube_image_acks')";
|
||||
auto q=[&](const std::string& sql){return db.Query(sql,rows)&&!db.warnings&&rows.size()==1&&rows[0].size()==1;};
|
||||
return q("SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN "+names)&&rows[0][0]=="2"&&
|
||||
q("SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA=DATABASE() AND ENGINE='InnoDB' AND TABLE_NAME IN "+names)&&rows[0][0]=="2"&&
|
||||
q("SELECT version FROM port_cube_image_ack_version WHERE id=1")&&rows[0][0]=="1";
|
||||
}
|
||||
template<class DB> class ImageAckStore {
|
||||
DB& db;Lookup lookup;
|
||||
static std::string X(const std::string& s){return "X'"+PortEconomy::Hex(s.data(),s.size())+"'";}
|
||||
public:
|
||||
enum Result {Retry,Refused,Stored};
|
||||
ImageAckStore(DB& d,Lookup p):db(d),lookup(std::move(p)){}
|
||||
Result AcknowledgeLive(const Batch& b,const OwnerGrant& grant,const std::string& image) {
|
||||
InventoryImage decoded;
|
||||
if(!Validate(b)||!Valid(grant)||!Matches(grant.binding,b)||!DecodeInventoryImage(image,decoded,lookup))return Refused;
|
||||
if(!ImageAckSchema(db))return Retry;
|
||||
OwnerStore<DB> owner(db,lookup);FenceStore<DB> fence(db,lookup);std::string current;
|
||||
// Resync holds the account, fence and current SQL inventory on the same
|
||||
// pinned transaction. Callback writes roll back with its COMMIT failure.
|
||||
const auto result=fence.Resync(b,current,[&](const std::string& actual)->bool {
|
||||
if(actual!=image||!owner.LiveImageWithin(b,grant,image))return false;
|
||||
PortEconomy::Rows rows;
|
||||
auto q=[&](const std::string& sql){return db.Query(sql,rows)&&!db.warnings;};
|
||||
// ACK cannot create the initial issued image or acknowledge a
|
||||
// changed saved image, even when the current SQL happens to match.
|
||||
if(!q("SELECT phase,image FROM port_cube_fences WHERE pid="+std::to_string(b.player)+" FOR UPDATE")||
|
||||
rows.size()!=1||rows[0]!=std::vector<std::string>{"RESYNC",image})return false;
|
||||
const auto body=Encode(b),binding=EncodeOwnerGrant(grant);
|
||||
if(!q("SELECT body,owner_grant,image FROM port_cube_image_acks WHERE request='"+b.token+"' FOR UPDATE"))return false;
|
||||
if(!rows.empty())return rows.size()==1&&rows[0]==std::vector<std::string>{body,binding,image};
|
||||
return q("INSERT INTO port_cube_image_acks(request,body,owner_grant,image) VALUES('"+b.token+"',"+X(body)+","+X(binding)+","+X(image)+")")&&db.affected==1;
|
||||
});
|
||||
return result==FenceStore<DB>::Done?Stored:result==FenceStore<DB>::Retry?Retry:Refused;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
namespace PortCube {
|
||||
// Legacy game allocation uses an exclusive upper bound. DB range collision
|
||||
// checks are inclusive, so even touching ranges are rejected for handoff.
|
||||
struct ItemIDRange { uint32_t minimum=0, maximum=0, usable=0; };
|
||||
struct ItemIDPlan {
|
||||
std::vector<uint32_t> ids;
|
||||
uint32_t next=0;
|
||||
bool spare=false;
|
||||
};
|
||||
inline bool ValidItemIDRange(const ItemIDRange& r) {
|
||||
return r.minimum && r.minimum<=r.usable && r.usable<r.maximum;
|
||||
}
|
||||
inline bool PlanItemIDs(const ItemIDRange& active,uint32_t next,
|
||||
const ItemIDRange& spare,unsigned count,ItemIDPlan& out) {
|
||||
// No partial output, wraparound, allocation of the sentinel maximum, or
|
||||
// speculative switch when all IDs already fit in the active range.
|
||||
if(!count||count>100||!ValidItemIDRange(active)||
|
||||
next<active.usable||next>active.maximum)return false;
|
||||
const uint64_t available=uint64_t(active.maximum)-next;
|
||||
const bool switchRange=count>available;
|
||||
if(switchRange && (!ValidItemIDRange(spare)||
|
||||
!(active.maximum<spare.minimum||spare.maximum<active.minimum)||
|
||||
uint64_t(count)-available>uint64_t(spare.maximum)-spare.usable))return false;
|
||||
ItemIDPlan plan;plan.ids.reserve(count);
|
||||
uint32_t cursor=next;
|
||||
for(unsigned i=0;i<count;++i) {
|
||||
if(!plan.spare&&cursor==active.maximum){plan.spare=true;cursor=spare.usable;}
|
||||
plan.ids.push_back(cursor++);
|
||||
}
|
||||
plan.next=cursor;out=std::move(plan);return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
#pragma once
|
||||
#include "cube_craft.h"
|
||||
namespace PortCube {
|
||||
inline bool CraftImage(const Batch& b,const CraftReceipt& receipt,uint64_t credits,const Lookup& lookup,std::string& out) {
|
||||
if(receipt.result!="ok"||!ValidateCraftReceipt(b,receipt,lookup)||receipt.fee>b.gold||
|
||||
credits>uint64_t(PortEconomy::GoldLimit)-(b.gold-receipt.fee))return false;
|
||||
std::string rolls(b.attempts,char(100));for(unsigned i=0;i<receipt.successes;++i)rolls[i]=1;
|
||||
const auto plan=SettlePlan(b,rolls,lookup);if(plan.result!="ok")return false;
|
||||
InventoryImage image;image.gold=b.gold-receipt.fee+credits;image.items=b.inventory;
|
||||
for(auto& item:image.items){item.usable=true;for(const auto& take:plan.takes)if(take.id==item.value.id){if(take.count>item.value.count)return false;item.value.count-=take.count;}}
|
||||
image.items.erase(std::remove_if(image.items.begin(),image.items.end(),[](const Item& i){return !i.value.count;}),image.items.end());
|
||||
image.items.insert(image.items.end(),receipt.awards.begin(),receipt.awards.end());
|
||||
std::sort(image.items.begin(),image.items.end(),[](const Item& a,const Item& c){return a.cell<c.cell;});
|
||||
const auto bytes=EncodeInventoryImage(image);InventoryImage decoded;if(!DecodeInventoryImage(bytes,decoded,lookup))return false;out=bytes;return true;
|
||||
}
|
||||
// Transport state only: adapter must apply/read back and remain held throughout.
|
||||
class LiveImageFlow {
|
||||
public: enum Stage {Idle,Waiting,Ready,Held,Applied,AckWaiting,Acknowledged};
|
||||
private: Stage stage=Idle;Handshake identity;std::string expected;
|
||||
public:
|
||||
Stage State()const{return stage;}bool MayRetry()const{return stage==Waiting;}
|
||||
const std::string& Image()const{return expected;}
|
||||
void Invalidate(){stage=Held;}
|
||||
bool Start(const Handshake& bound,const Batch& b,const CraftReceipt& receipt,uint64_t credits,const Lookup& lookup,bool sealed) {
|
||||
auto f=bound;f.message=Message::LiveImageRequest;f.status=Status::None;f.body.clear();
|
||||
if(stage!=Idle||!sealed||!ValidHandshake(f)||f.account!=b.account||f.player!=b.player||f.epoch!=b.epoch||f.owner!=b.owner||f.token!=b.token||!CraftImage(b,receipt,credits,lookup,expected))return false;
|
||||
identity=std::move(f);stage=Waiting;return true;
|
||||
}
|
||||
Handshake Request()const{return identity;}
|
||||
bool MarkApplied(const std::string& readback) {
|
||||
if(stage!=Ready||readback!=expected){stage=Held;return false;}stage=Applied;return true;
|
||||
}
|
||||
bool BeginAcknowledge(const std::string& readback) {
|
||||
if(stage!=Applied||readback!=expected){stage=Held;return false;}stage=AckWaiting;return true;
|
||||
}
|
||||
bool MayAcknowledge()const{return stage==AckWaiting;}
|
||||
Handshake Acknowledgement()const {
|
||||
auto f=identity;f.message=Message::LiveImageAck;f.body=expected;return f;
|
||||
}
|
||||
bool Answer(const Handshake& f) {
|
||||
if(!ValidHandshake(f)||!SameIdentity(f,identity)||f.cookie!=identity.cookie)return false;
|
||||
if(f.message==Message::LiveImageAckAnswer) {
|
||||
if(stage!=AckWaiting&&stage!=Acknowledged)return false;
|
||||
if(f.status==Status::Held)return stage==AckWaiting;
|
||||
if(f.status!=Status::LiveImageAcknowledged)return false;
|
||||
if(f.body!=expected){stage=Held;return false;}stage=Acknowledged;return true;
|
||||
}
|
||||
if((stage!=Waiting&&stage!=Ready&&stage!=Applied&&stage!=AckWaiting&&stage!=Acknowledged)||f.message!=Message::LiveImageAnswer)return false;
|
||||
if(f.status==Status::Held)return stage==Waiting;
|
||||
if(f.status!=Status::LiveImageReady)return false;
|
||||
if(f.body!=expected){stage=Held;return false;}if(stage==Waiting)stage=Ready;return true;
|
||||
}
|
||||
};
|
||||
// Terminal SQL transport only. A Released result retains both actor and DB
|
||||
// memory holds; it is NOT a resume grant or permission to enable item saves.
|
||||
class LiveReleaseFlow {
|
||||
public: enum Stage {Idle,Waiting,Released,Held};
|
||||
private: Stage stage=Idle;Handshake request;
|
||||
public:
|
||||
Stage State()const{return stage;}
|
||||
bool MayRetry()const{return stage==Waiting;}
|
||||
void Invalidate(){stage=Held;}
|
||||
bool Start(const LiveImageFlow& image,bool locallyReady) {
|
||||
if(stage!=Idle||!locallyReady||image.State()!=LiveImageFlow::Acknowledged)return false;
|
||||
auto f=image.Acknowledgement();f.message=Message::LiveReleaseRequest;
|
||||
if(!ValidHandshake(f))return false;
|
||||
request=std::move(f);stage=Waiting;return true;
|
||||
}
|
||||
Handshake Request()const{return request;}
|
||||
bool Answer(const Handshake& f) {
|
||||
if((stage!=Waiting&&stage!=Released)||!ValidHandshake(f)||f.message!=Message::LiveReleaseAnswer||
|
||||
!SameIdentity(f,request)||f.cookie!=request.cookie)return false;
|
||||
if(f.status==Status::Held)return stage==Waiting;
|
||||
if(f.status!=Status::LiveReleased)return false;
|
||||
if(f.body!=request.body){stage=Held;return false;}
|
||||
stage=Released;return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
namespace PortCube {
|
||||
// Preparation admission is conservative, not a change to expiry/reward rules.
|
||||
// No bit grants permission to pause arbitrary timers or drop a mutation.
|
||||
enum Hazard : uint32_t { ItemClock=1,ItemBusy=2,QuestTimer=4,QuestRunning=8,
|
||||
Switcher=16,Party=32,Combat=64,LifeCycle=128,MissingState=256 };
|
||||
enum Mutation : uint32_t { ItemWrite=1,GoldWrite=2,QuestWrite=4,ContextChanged=8,LifecycleWrite=16 };
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
#pragma once
|
||||
#include "cube_owner_types.h"
|
||||
#include "cube_gold_store.h"
|
||||
#include "cube_image.h"
|
||||
#include <cerrno>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
namespace PortCube {
|
||||
inline std::string OwnerBootNonce() {
|
||||
unsigned char bytes[16];const int fd=open("/dev/urandom",O_RDONLY);if(fd<0)return {};size_t at=0;
|
||||
while(at<sizeof(bytes)){auto n=read(fd,bytes+at,sizeof(bytes)-at);if(n<0&&errno==EINTR)continue;if(n<=0){close(fd);return {};}at+=size_t(n);}close(fd);
|
||||
const auto s=PortEconomy::Hex(bytes,sizeof(bytes));return Identity(s)?s:std::string{};
|
||||
}
|
||||
// DB-main/direct-session authority. A connection-scoped MySQL advisory lock
|
||||
// fences competing brokers; each new boot OR SQL connection advances generation.
|
||||
// There is no wall-clock expiry, auto-adoption, currency write or thaw here.
|
||||
template<class DB> class OwnerStore {
|
||||
DB& db;Lookup lookup;using Rows=PortEconomy::Rows;
|
||||
static std::string N(uint64_t n){return std::to_string(n);}
|
||||
bool Q(const std::string& s,Rows& r){return db.Query(s,r)&&!db.warnings;}
|
||||
bool Run(const std::string& s){Rows r;return Q(s,r);}
|
||||
bool Change(const std::string& s){return Run(s)&&db.affected==1;}
|
||||
struct Guard {DB& db;~Guard(){db.Rollback();}};
|
||||
bool Account(uint32_t id){Rows r;return Run("INSERT INTO port_economy_account_lock(account) VALUES("+N(id)+") ON DUPLICATE KEY UPDATE account=VALUES(account)")&&Q("SELECT account FROM port_economy_account_lock WHERE account="+N(id)+" FOR UPDATE",r)&&r.size()==1;}
|
||||
bool Session(uint64_t& connection,uint64_t& holder) {
|
||||
Rows r;holder=0;
|
||||
if(!Q("SELECT CONNECTION_ID(),IS_USED_LOCK(CONCAT('m2_cube:',DATABASE()))",r)||r.size()!=1||r[0].size()!=2||!PortEconomy::Number(r[0][0],connection)||!connection)return false;
|
||||
return r[0][1].empty()||PortEconomy::Number(r[0][1],holder);
|
||||
}
|
||||
bool LeaderRow(const OwnerLeader& l) {
|
||||
uint64_t connection=0,holder=0;Rows r;
|
||||
return Valid(l)&&Session(connection,holder)&&connection==l.connection&&holder==connection&&
|
||||
Q("SELECT generation,boot,connection_id FROM port_cube_owner_broker WHERE id=1 FOR UPDATE",r)&&r.size()==1&&r[0]==std::vector<std::string>{N(l.generation),l.boot,N(l.connection)};
|
||||
}
|
||||
bool LeaseRows(const Batch& b,Rows& r){return Q("SELECT account,pid,body,revision,generation,boot,connection_id,peer,binding,original_peer,original_binding,phase,revoked_generation,reason FROM port_cube_owner_leases WHERE request='"+b.token+"' FOR UPDATE",r);}
|
||||
static bool DecodeLease(const Batch& b,const Rows& rows,OwnerGrant& active,GoldSourceBinding& original,uint32_t& originalPeer,std::string& phase,uint64_t& revoked) {
|
||||
active={};original={};originalPeer=0;revoked=0;
|
||||
if(rows.size()!=1||rows[0].size()!=14)return false;const auto& r=rows[0];uint64_t peer=0,oldPeer=0,reason=0;
|
||||
if(r[0]!=N(b.account)||r[1]!=N(b.player)||r[2]!=Encode(b)||!PortEconomy::Number(r[3],active.revision)||!PortEconomy::Number(r[4],active.leader.generation)||
|
||||
!PortEconomy::Number(r[6],active.leader.connection)||!PortEconomy::Number(r[7],peer,UINT32_MAX)||!PortEconomy::Number(r[9],oldPeer,UINT32_MAX)||
|
||||
!DecodeGoldSourceBinding(r[8],active.binding)||!DecodeGoldSourceBinding(r[10],original)||!Matches(active.binding,b)||!Matches(original,b)||
|
||||
!PortEconomy::Number(r[12],revoked)||!PortEconomy::Number(r[13],reason,3))return false;
|
||||
active.peer=uint32_t(peer);active.leader.boot=r[5];originalPeer=uint32_t(oldPeer);phase=r[11];
|
||||
return Valid(active)&&originalPeer&&(phase=="LIVE"||phase=="REVOKED"||phase=="ADOPTED")&&((phase=="REVOKED")==bool(revoked))&&((phase=="REVOKED")==bool(reason));
|
||||
}
|
||||
static bool Same(const OwnerGrant& a,const OwnerGrant& b){return SameOwnerGrant(a,b);}
|
||||
public:
|
||||
enum Result {Retry,Refused,Busy,Acquired,Revoked,Adopted};
|
||||
OwnerStore(DB& d,Lookup p):db(d),lookup(std::move(p)){}
|
||||
bool Ready(){GoldIntentStore<DB> gold(db,lookup);return gold.Ready()&&OwnerSchema(db)==1;}
|
||||
Result Acquire(std::string boot,OwnerLeader& leader) {
|
||||
leader={};if(!Identity(boot))return Refused;if(!Ready())return Retry;
|
||||
uint64_t connection=0,holder=0;if(!Session(connection,holder))return Retry;
|
||||
Rows rows;
|
||||
if(holder!=connection) {
|
||||
if(!Q("SELECT GET_LOCK(CONCAT('m2_cube:',DATABASE()),0)",rows)||rows.size()!=1||rows[0].size()!=1)return Retry;
|
||||
if(rows[0][0]!="1")return Busy;
|
||||
}
|
||||
if(!db.Begin())return Retry;Guard guard{db};
|
||||
if(!Q("SELECT generation,boot,connection_id FROM port_cube_owner_broker WHERE id=1 FOR UPDATE",rows)||rows.size()!=1||rows[0].size()!=3)return Retry;
|
||||
uint64_t generation=0,oldConnection=0;
|
||||
if(!PortEconomy::Number(rows[0][0],generation)||!PortEconomy::Number(rows[0][2],oldConnection))return Refused;
|
||||
if(generation&&(!Identity(rows[0][1])||!oldConnection))return Refused;
|
||||
if(!generation&&(rows[0][1]!=std::string(32,'0')||oldConnection))return Refused;
|
||||
if(generation&&rows[0][1]==boot&&oldConnection==connection){leader={boot,generation,connection};return Acquired;}
|
||||
if(generation==UINT64_MAX)return Refused;
|
||||
if(!Change("UPDATE port_cube_owner_broker SET generation="+N(generation+1)+",boot='"+boot+"',connection_id="+N(connection)+" WHERE id=1 AND generation="+N(generation))||!db.Commit())return Retry;
|
||||
leader={boot,generation+1,connection};return Acquired;
|
||||
}
|
||||
bool Current(const OwnerLeader& l){if(!Ready()||!db.Begin())return false;Guard g{db};return LeaderRow(l);}
|
||||
// Called INSIDE FenceStore::Begin's account transaction, after item locks.
|
||||
// Replay can only validate an existing identical row, never invent one.
|
||||
bool BindWithin(const Batch& b,const OwnerGrant& grant,bool replay) {
|
||||
if(!Validate(b)||!Valid(grant)||grant.revision!=1||!Matches(grant.binding,b)||!LeaderRow(grant.leader))return false;
|
||||
Rows rows;if(!LeaseRows(b,rows))return false;
|
||||
if(!rows.empty()) {
|
||||
OwnerGrant existing;GoldSourceBinding original;uint32_t peer=0;std::string phase;uint64_t revoked=0;
|
||||
return DecodeLease(b,rows,existing,original,peer,phase,revoked)&&phase=="LIVE"&&Same(existing,grant)&&peer==grant.peer&&EncodeGoldSourceBinding(original)==EncodeGoldSourceBinding(grant.binding);
|
||||
}
|
||||
if(replay)return false;
|
||||
if(!Q("SELECT request FROM port_cube_owner_leases WHERE account="+N(b.account)+" OR pid="+N(b.player)+" FOR UPDATE",rows)||!rows.empty())return false;
|
||||
const auto body=Encode(b),binding=EncodeGoldSourceBinding(grant.binding);
|
||||
return Change("INSERT INTO port_cube_owner_leases(request,account,pid,body,revision,generation,boot,connection_id,peer,binding,original_peer,original_binding,phase,revoked_generation,reason) VALUES('"+b.token+"',"+N(b.account)+","+N(b.player)+",X'"+PortEconomy::Hex(body.data(),body.size())+"',1,"+N(grant.leader.generation)+",'"+grant.leader.boot+"',"+N(grant.leader.connection)+","+N(grant.peer)+",X'"+PortEconomy::Hex(binding.data(),binding.size())+"',"+N(grant.peer)+",X'"+PortEconomy::Hex(binding.data(),binding.size())+"','LIVE',0,0)");
|
||||
}
|
||||
bool Check(const Batch& b,const OwnerGrant& grant) {
|
||||
if(!Ready()||!db.Begin())return false;Guard guard{db};if(!Account(b.account)||!LeaderRow(grant.leader))return false;
|
||||
Rows rows;OwnerGrant active;GoldSourceBinding original;uint32_t peer=0;std::string phase;uint64_t revoked=0;
|
||||
return LeaseRows(b,rows)&&DecodeLease(b,rows,active,original,peer,phase,revoked)&&phase!="REVOKED"&&Same(active,grant);
|
||||
}
|
||||
// Called inside Prepare/Execute after the account lock, never via a separate
|
||||
// reconnectable preflight. The original live source must be sealed first.
|
||||
bool CraftWithin(const Batch& b,const OwnerGrant& grant) {
|
||||
if(!Validate(b)||!Valid(grant)||!Matches(grant.binding,b)||!Ready()||!LeaderRow(grant.leader))return false;
|
||||
Rows rows;OwnerGrant active;GoldSourceBinding original;uint32_t peer=0;std::string phase;uint64_t revoked=0;
|
||||
if(!LeaseRows(b,rows)||!DecodeLease(b,rows,active,original,peer,phase,revoked)||phase!="LIVE"||!Same(active,grant)||peer!=grant.peer||EncodeGoldSourceBinding(original)!=EncodeGoldSourceBinding(grant.binding))return false;
|
||||
if(!Q("SELECT account,epoch,owner,request,phase,body,drain_state FROM port_cube_fences WHERE pid="+N(b.player)+" FOR UPDATE",rows)||rows.size()!=1||rows[0]!=std::vector<std::string>{N(b.account),N(b.epoch),b.owner,b.token,"FROZEN",Encode(b),"1"})return false;
|
||||
std::vector<GoldRecord> records;if(!GoldRecords(db,b,records))return false;
|
||||
std::vector<std::string> events;for(const auto& record:records)events.push_back(record.intent.event);
|
||||
const std::vector<std::string> proof={N(b.account),N(b.player),N(b.epoch),b.owner,N(original.session),N(original.cookie),N(original.handle),EncodeGoldManifest(events)};
|
||||
return Q("SELECT account,pid,epoch,owner,session,cookie,handle,manifest FROM port_cube_gold_sources WHERE request='"+b.token+"' FOR UPDATE",rows)&&rows.size()==1&&rows[0]==proof;
|
||||
}
|
||||
// Inside Fence.Resync's account transaction on the SAME pinned connection.
|
||||
// A grant alone is insufficient: recheck original source, verified receipt,
|
||||
// current wallet (including zero-credit batches), and all surviving ID locks.
|
||||
private:
|
||||
bool OwnedImageWithin(const Batch& b,const OwnerGrant& grant,const std::string& image,bool live,bool released=false) {
|
||||
if(!Validate(b)||!Valid(grant)||!Matches(grant.binding,b)||!Ready()||!LeaderRow(grant.leader))return false;
|
||||
Rows rows;OwnerGrant active;GoldSourceBinding original;uint32_t peer=0;std::string phase;uint64_t revoked=0;
|
||||
if(released) {
|
||||
if(!ReleasedWithin(b,grant))return false;
|
||||
original=grant.binding;peer=grant.peer;
|
||||
} else {
|
||||
if(!LeaseRows(b,rows)||!DecodeLease(b,rows,active,original,peer,phase,revoked)||phase!=(live?"LIVE":"ADOPTED")||!Same(active,grant))return false;
|
||||
if(live&&(peer!=grant.peer||EncodeGoldSourceBinding(original)!=EncodeGoldSourceBinding(grant.binding)))return false;
|
||||
}
|
||||
std::vector<GoldRecord> records;if(!GoldRecords(db,b,records))return false;
|
||||
std::vector<std::string> events;for(const auto& record:records){if(!record.applied)return false;events.push_back(record.intent.event);}
|
||||
const std::vector<std::string> proof={N(b.account),N(b.player),N(b.epoch),b.owner,N(original.session),N(original.cookie),N(original.handle),EncodeGoldManifest(events)};
|
||||
if(!Q("SELECT account,pid,epoch,owner,session,cookie,handle,manifest FROM port_cube_gold_sources WHERE request='"+b.token+"' FOR UPDATE",rows)||rows.size()!=1||rows[0]!=proof)return false;
|
||||
typename BatchStore<DB>::Receipt receipt;
|
||||
if(!Q("SELECT body,rolls,state,result,successes,fee,awards FROM port_cube_requests WHERE token='"+b.token+"' AND account="+N(b.account)+" AND pid="+N(b.player)+" FOR UPDATE",rows)||rows.size()!=1||!BatchStore<DB>::DoneReceipt(b,rows[0],receipt)||receipt.result!="ok")return false;
|
||||
const auto plan=SettlePlan(b,rows[0][1],lookup);Writer planned,awarded;planned.items(plan.awards);awarded.items(receipt.awards);
|
||||
if(plan.result!="ok"||plan.fee!=receipt.fee||plan.successes!=receipt.successes||planned.data!=awarded.data)return false;
|
||||
uint64_t gold=b.gold-receipt.fee;
|
||||
for(const auto& record:records){if(record.before!=gold)return false;gold=record.after;}
|
||||
if(!Q("SELECT gold FROM player WHERE id="+N(b.player)+" AND account_id="+N(b.account)+" FOR UPDATE",rows)||rows.size()!=1||rows[0]!=std::vector<std::string>{N(gold)})return false;
|
||||
if(!Q("SELECT id,pid,epoch,request FROM port_cube_item_fences WHERE pid="+N(b.player)+" FOR UPDATE",rows)||rows.size()>8517)return false;
|
||||
if(released&&!rows.empty())return false;
|
||||
std::set<uint32_t> locks;
|
||||
for(const auto& row:rows){uint64_t id=0;if(row.size()!=4||!PortEconomy::Number(row[0],id,UINT32_MAX)||!id||row[1]!=N(b.player)||row[2]!=N(b.epoch)||row[3]!=b.token||!locks.insert(uint32_t(id)).second)return false;}
|
||||
for(const auto& item:b.inventory)if(!released&&!locks.count(item.value.id))return false;
|
||||
std::set<uint32_t> reserved;for(const auto& reward:b.rewards){if(!released&&!locks.count(reward.id))return false;reserved.insert(reward.id);}
|
||||
if(!Q("SELECT id,request FROM port_economy_item_reservations WHERE request='"+b.token+"' FOR UPDATE",rows)||rows.size()!=reserved.size())return false;
|
||||
for(const auto& row:rows){uint64_t id=0;if(row.size()!=2||!PortEconomy::Number(row[0],id,UINT32_MAX)||row[1]!=b.token||!reserved.erase(uint32_t(id)))return false;}
|
||||
if(!reserved.empty()||!Q("SELECT id FROM item WHERE owner_id="+N(b.player)+" AND window NOT IN ('MALL','SAFEBOX') FOR UPDATE",rows)||rows.size()>4096)return false;
|
||||
for(const auto& row:rows){uint64_t id=0;if(row.size()!=1||!PortEconomy::Number(row[0],id,UINT32_MAX)||!id||(!released&&!locks.count(uint32_t(id))))return false;}
|
||||
InventoryImage expected;expected.gold=gold;expected.items=b.inventory;
|
||||
for(auto& item:expected.items){item.usable=true;for(const auto& take:plan.takes)if(take.id==item.value.id){if(take.count>item.value.count)return false;item.value.count-=take.count;}}
|
||||
expected.items.erase(std::remove_if(expected.items.begin(),expected.items.end(),[](const Item& item){return !item.value.count;}),expected.items.end());
|
||||
expected.items.insert(expected.items.end(),receipt.awards.begin(),receipt.awards.end());std::sort(expected.items.begin(),expected.items.end(),[](const Item& a,const Item& c){return a.cell<c.cell;});
|
||||
InventoryImage decoded;return DecodeInventoryImage(image,decoded,lookup)&&EncodeInventoryImage(expected)==image;
|
||||
}
|
||||
public:
|
||||
bool ImageWithin(const Batch& b,const OwnerGrant& grant,const std::string& image){return OwnedImageWithin(b,grant,image,false);}
|
||||
bool LiveImageWithin(const Batch& b,const OwnerGrant& grant,const std::string& image){return OwnedImageWithin(b,grant,image,true);}
|
||||
// Caller holds a released fence/account transaction and checks exact
|
||||
// terminal history. No lease resurrection, save permission or asset writes.
|
||||
bool ReleasedImageWithin(const Batch& b,const OwnerGrant& grant,const std::string& image){return OwnedImageWithin(b,grant,image,true,true);}
|
||||
// Historical terminal reply only, inside the caller's account transaction.
|
||||
// Exact durable receipt is checked by that caller; never clear a newer hold.
|
||||
bool ReleasedWithin(const Batch& b,const OwnerGrant& grant) {
|
||||
if(!Validate(b)||!Valid(grant)||!Matches(grant.binding,b)||!Ready()||!LeaderRow(grant.leader))return false;
|
||||
Rows rows;return Q("SELECT request FROM port_cube_owner_leases WHERE account="+N(b.account)+" OR pid="+N(b.player)+" OR request='"+b.token+"' FOR UPDATE",rows)&&rows.empty();
|
||||
}
|
||||
bool Inspect(const Batch& b,const OwnerLeader& l,OwnerGrant& active,std::string& phase,uint64_t& revoked) {
|
||||
active={};phase.clear();revoked=0;
|
||||
if(!Validate(b)||!Ready()||!db.Begin())return false;Guard guard{db};
|
||||
if(!Account(b.account)||!LeaderRow(l))return false;
|
||||
Rows rows;GoldSourceBinding original;uint32_t peer=0;
|
||||
return LeaseRows(b,rows)&&DecodeLease(b,rows,active,original,peer,phase,revoked);
|
||||
}
|
||||
// reason 1/2 is a trusted DB peer-gone/account-owner-ended callback, not a
|
||||
// packet/client boolean. reason 3 requires a strictly newer broker generation.
|
||||
Result Revoke(const Batch& b,const OwnerLeader& l,unsigned reason,const OwnerGrant* lost,OwnerGrant& revokedGrant) {
|
||||
revokedGrant={};if(!Validate(b)||!Valid(l)||reason<1||reason>3||(reason!=3&&(!lost||!Valid(*lost))))return Refused;
|
||||
if(!Ready()||!db.Begin())return Retry;Guard guard{db};if(!Account(b.account)||!LeaderRow(l))return Retry;
|
||||
Rows rows;OwnerGrant active;GoldSourceBinding original;uint32_t peer=0;std::string phase;uint64_t revoked=0;
|
||||
if(!LeaseRows(b,rows)||!DecodeLease(b,rows,active,original,peer,phase,revoked))return Refused;
|
||||
if(reason==3){if(active.leader.generation>=l.generation)return Refused;}
|
||||
else {auto expected=*lost;if(phase=="REVOKED"&&lost->revision!=UINT64_MAX&&active.revision==lost->revision+1)expected.revision=active.revision;
|
||||
if(!Same(active,expected)||active.leader.boot!=l.boot||active.leader.generation!=l.generation||active.leader.connection!=l.connection)return Refused;}
|
||||
if(phase=="REVOKED"&&revoked==l.generation){revokedGrant=active;return Revoked;}
|
||||
if(active.revision==UINT64_MAX)return Refused;
|
||||
if(!Change("UPDATE port_cube_owner_leases SET phase='REVOKED',revision="+N(active.revision+1)+",revoked_generation="+N(l.generation)+",reason="+N(reason)+" WHERE request='"+b.token+"' AND revision="+N(active.revision))||!db.Commit())return Retry;
|
||||
active.revision++;revokedGrant=active;return Revoked;
|
||||
}
|
||||
Result Adopt(const Batch& b,const OwnerLeader& l,uint64_t revokedRevision,uint32_t peer,const GoldSourceBinding& target,OwnerGrant& grant) {
|
||||
grant={};if(!Validate(b)||!Valid(l)||!revokedRevision||revokedRevision==UINT64_MAX||!peer||!Matches(target,b)||EncodeGoldSourceBinding(target).empty())return Refused;
|
||||
if(!Ready()||!db.Begin())return Retry;Guard guard{db};if(!Account(b.account)||!LeaderRow(l))return Retry;
|
||||
Rows rows;OwnerGrant active;GoldSourceBinding original;uint32_t originalPeer=0;std::string phase;uint64_t revoked=0;
|
||||
if(!LeaseRows(b,rows)||!DecodeLease(b,rows,active,original,originalPeer,phase,revoked))return Refused;
|
||||
OwnerGrant expected{l,target,peer,revokedRevision+1};
|
||||
if(phase=="ADOPTED") {if(!Same(active,expected))return Refused;grant=active;return Adopted;}
|
||||
if(phase!="REVOKED"||revoked!=l.generation||active.revision!=revokedRevision)return Refused;
|
||||
if(target.session==original.session||target.session==active.binding.session)return Refused;
|
||||
if(!Q("SELECT account,epoch,owner,request,phase,body,drain_state FROM port_cube_fences WHERE pid="+N(b.player)+" FOR UPDATE",rows)||rows.size()!=1||rows[0].size()!=7)return Refused;
|
||||
const auto fence=rows[0];
|
||||
if(fence[0]!=N(b.account)||fence[1]!=N(b.epoch)||fence[2]!=b.owner||fence[3]!=b.token||fence[5]!=Encode(b)||fence[6]!="1"||(fence[4]!="FROZEN"&&fence[4]!="RESYNC"))return Refused;
|
||||
std::vector<GoldRecord> records;if(!GoldRecords(db,b,records))return Refused;
|
||||
std::vector<std::string> events;for(const auto& r:records)events.push_back(r.intent.event);
|
||||
const std::vector<std::string> proof={N(b.account),N(b.player),N(b.epoch),b.owner,N(original.session),N(original.cookie),N(original.handle),EncodeGoldManifest(events)};
|
||||
if(!Q("SELECT account,pid,epoch,owner,session,cookie,handle,manifest FROM port_cube_gold_sources WHERE request='"+b.token+"' FOR UPDATE",rows)||rows.size()!=1||rows[0]!=proof)return Refused;
|
||||
uint64_t expectedGold=0;if(GoldCreditBase(db,b,expectedGold)!=1)return Refused;
|
||||
bool pending=false;uint64_t future=expectedGold;
|
||||
for(const auto& r:records)if(r.applied){if(pending||r.before!=expectedGold)return Refused;expectedGold=future=r.after;}else{pending=true;if(future>uint64_t(PortEconomy::GoldLimit)-r.intent.amount)return Refused;future+=r.intent.amount;}
|
||||
if(fence[4]=="RESYNC"&&pending)return Refused;
|
||||
if(!Q("SELECT gold FROM player WHERE id="+N(b.player)+" AND account_id="+N(b.account)+" FOR UPDATE",rows)||rows.size()!=1||rows[0].size()!=1||rows[0][0]!=N(expectedGold))return Refused;
|
||||
const auto binding=EncodeGoldSourceBinding(target);
|
||||
if(!Change("UPDATE port_cube_owner_leases SET phase='ADOPTED',revision="+N(expected.revision)+",generation="+N(l.generation)+",boot='"+l.boot+"',connection_id="+N(l.connection)+",peer="+N(peer)+",binding=X'"+PortEconomy::Hex(binding.data(),binding.size())+"',revoked_generation=0,reason=0 WHERE request='"+b.token+"' AND revision="+N(revokedRevision)+" AND phase='REVOKED'")||!db.Commit())return Retry;
|
||||
grant=std::move(expected);return Adopted; // still held; no image/currency/load/thaw side effect
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include "cube_gold_source.h"
|
||||
#include "economy_store.h"
|
||||
namespace PortCube {
|
||||
struct OwnerLeader {std::string boot;uint64_t generation=0,connection=0;};
|
||||
inline bool Valid(const OwnerLeader& l){return Identity(l.boot)&&l.generation&&l.connection;}
|
||||
struct OwnerGrant {OwnerLeader leader;GoldSourceBinding binding;uint32_t peer=0;uint64_t revision=0;};
|
||||
inline bool Valid(const OwnerGrant& g){return Valid(g.leader)&&g.peer&&g.revision&&!EncodeGoldSourceBinding(g.binding).empty();}
|
||||
inline bool SameOwnerGrant(const OwnerGrant& a,const OwnerGrant& b){return a.leader.boot==b.leader.boot&&a.leader.generation==b.leader.generation&&a.leader.connection==b.leader.connection&&a.peer==b.peer&&a.revision==b.revision&&EncodeGoldSourceBinding(a.binding)==EncodeGoldSourceBinding(b.binding);}
|
||||
constexpr unsigned OwnerGrantBytes=160;
|
||||
inline std::string EncodeOwnerGrant(const OwnerGrant& g) {
|
||||
if(!Valid(g))return {};Writer w;w.data="CRG1";w.data+=g.leader.boot;w.n(g.leader.generation,8);w.n(g.leader.connection,8);w.n(g.peer,4);w.n(g.revision,8);w.data+=EncodeGoldSourceBinding(g.binding);return w.data;
|
||||
}
|
||||
inline bool DecodeOwnerGrant(const std::string& body,OwnerGrant& grant) {
|
||||
grant={};if(body.size()!=OwnerGrantBytes||body.substr(0,4)!="CRG1")return false;
|
||||
Reader r(body);OwnerGrant g;r.at=4;g.leader.boot=body.substr(r.at,32);r.at+=32;
|
||||
g.leader.generation=r.n(8);g.leader.connection=r.n(8);g.peer=uint32_t(r.n(4));g.revision=r.n(8);
|
||||
if(!r.ok||!DecodeGoldSourceBinding(body.substr(r.at),g.binding)||EncodeOwnerGrant(g)!=body)return false;grant=std::move(g);return true;
|
||||
}
|
||||
template<class DB> int OwnerSchema(DB& db) {
|
||||
PortEconomy::Rows rows;const std::string names="('port_cube_owner_version','port_cube_owner_broker','port_cube_owner_leases')";
|
||||
auto query=[&](const std::string& s){return db.Query(s,rows)&&!db.warnings&&rows.size()==1&&rows[0].size()==1;};
|
||||
if(!query("SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN "+names))return -1;
|
||||
if(rows[0][0]=="0")return 0;
|
||||
if(rows[0][0]!="3"||!query("SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA=DATABASE() AND ENGINE='InnoDB' AND TABLE_NAME IN "+names)||rows[0][0]!="3")return -1;
|
||||
if(!query("SELECT version FROM port_cube_owner_version WHERE id=1")||rows[0][0]!="1")return -1;return 1;
|
||||
}
|
||||
// No legacy/old-owner image ACK can remove item fences for a registered owner.
|
||||
// The adopted-owner image/thaw protocol is a separate required implementation.
|
||||
template<class DB> int OwnerReleaseStatus(DB& db,const Batch& b) {
|
||||
const int schema=OwnerSchema(db);if(schema<0)return -1;if(!schema)return 1;PortEconomy::Rows rows;
|
||||
if(!db.Query("SELECT request FROM port_cube_owner_leases WHERE request='"+b.token+"' OR pid="+std::to_string(b.player)+" FOR UPDATE",rows)||db.warnings)return -1;
|
||||
return rows.empty()?1:0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// PORT: GC93 bounded LE presentation only. Never a craft request or thaw ACK.
|
||||
namespace PortCubeView {
|
||||
constexpr unsigned Slots=225,Quickslots=36,Maximum=32768;
|
||||
constexpr int64_t GoldLimit=2000000000000000LL;
|
||||
struct Quickslot {uint8_t type=0;uint16_t cell=0;};
|
||||
inline bool operator==(const Quickslot& a,const Quickslot& b){return a.type==b.type&&a.cell==b.cell;}
|
||||
struct Item {
|
||||
uint16_t cell=0,count=0;uint32_t id=0,vnum=0,flags=0,anti=0;
|
||||
int32_t sockets[3]={};uint8_t types[7]={};int16_t values[7]={};uint8_t extra[69]={};
|
||||
};
|
||||
struct Frame {uint64_t epoch=0,gold=0;std::vector<Item> items;std::array<Quickslot,Quickslots> quickslots={};};
|
||||
inline bool Valid(const Frame& f) {
|
||||
if(!f.epoch||f.gold>uint64_t(GoldLimit)||f.items.size()>Slots)return false;
|
||||
int last=-1;std::set<uint32_t> ids;
|
||||
for(const auto& i:f.items)if(i.cell>=Slots||int(i.cell)<=last||!i.id||!i.vnum||!i.count||i.count>2000||!ids.insert(i.id).second)return false;else last=i.cell;
|
||||
for(const auto& q:f.quickslots)if(q.type>3||(!q.type&&q.cell))return false;
|
||||
return true;
|
||||
}
|
||||
struct Writer {std::string bytes;void n(uint64_t v,unsigned width){for(unsigned j=0;j<width;++j)bytes+=char(v>>(8*j));}};
|
||||
struct Reader {const std::string& bytes;size_t at=0;bool ok=true;uint64_t n(unsigned width){if(at+width>bytes.size()){ok=false;return 0;}uint64_t v=0;for(unsigned j=0;j<width;++j)v|=uint64_t(uint8_t(bytes[at++]))<<(8*j);return v;}};
|
||||
inline std::string Encode(const Frame& f) {
|
||||
if(!Valid(f))return {};Writer w;w.n(11,1);w.bytes+="CCP1";w.n(f.epoch,8);w.n(f.gold,8);w.n(f.items.size(),2);w.n(Quickslots,1);
|
||||
for(const auto& q:f.quickslots){w.n(q.type,1);w.n(q.cell,2);}
|
||||
for(const auto& i:f.items) {
|
||||
w.n(i.cell,2);w.n(i.count,2);w.n(i.id,4);w.n(i.vnum,4);w.n(i.flags,4);w.n(i.anti,4);
|
||||
for(auto v:i.sockets)w.n(uint32_t(v),4);
|
||||
for(unsigned j=0;j<7;++j){w.n(i.types[j],1);w.n(uint16_t(i.values[j]),2);}
|
||||
w.bytes.append(reinterpret_cast<const char*>(i.extra),69);
|
||||
}
|
||||
return w.bytes.size()+5<=Maximum?w.bytes:std::string{};
|
||||
}
|
||||
inline bool Decode(const std::string& bytes,Frame& out) {
|
||||
out={};if(bytes.size()<132||bytes.size()+5>Maximum||uint8_t(bytes[0])!=11||bytes.substr(1,4)!="CCP1")return false;
|
||||
Reader r{bytes};r.at=5;Frame f;f.epoch=r.n(8);f.gold=r.n(8);const auto count=r.n(2);
|
||||
if(count>Slots||r.n(1)!=Quickslots||bytes.size()!=132+122*count)return false;
|
||||
for(auto& q:f.quickslots){q.type=uint8_t(r.n(1));q.cell=uint16_t(r.n(2));}
|
||||
for(unsigned j=0;j<count;++j) {
|
||||
Item i;i.cell=uint16_t(r.n(2));i.count=uint16_t(r.n(2));i.id=uint32_t(r.n(4));i.vnum=uint32_t(r.n(4));i.flags=uint32_t(r.n(4));i.anti=uint32_t(r.n(4));
|
||||
for(auto& v:i.sockets){uint32_t bits=uint32_t(r.n(4));std::memcpy(&v,&bits,4);}
|
||||
for(unsigned k=0;k<7;++k){i.types[k]=uint8_t(r.n(1));uint16_t bits=uint16_t(r.n(2));std::memcpy(&i.values[k],&bits,2);}
|
||||
for(auto& v:i.extra)v=uint8_t(r.n(1));f.items.push_back(i);
|
||||
}
|
||||
if(!r.ok||r.at!=bytes.size()||!Valid(f)||Encode(f)!=bytes)return false;out=std::move(f);return true;
|
||||
}
|
||||
// Snapshot old bindings ONCE before installing any new items. Never bind a
|
||||
// consumed item's shortcut to a new reward merely reusing the same cell.
|
||||
inline bool Rebind(const std::vector<Item>& before,const Frame& after,const std::array<Quickslot,Quickslots>& original,std::array<Quickslot,Quickslots>& result) {
|
||||
if(!Valid(after))return false;std::set<uint16_t> cells;std::set<uint32_t> ids;
|
||||
for(const auto& i:before)if(i.cell>=Slots||!i.id||!cells.insert(i.cell).second||!ids.insert(i.id).second)return false;
|
||||
auto plan=original;
|
||||
for(auto& q:plan) {
|
||||
if(q.type>3||(!q.type&&q.cell))return false;if(q.type!=1||q.cell>=Slots)continue;
|
||||
const auto old=std::find_if(before.begin(),before.end(),[&](const Item& i){return i.cell==q.cell;});
|
||||
const auto next=old==before.end()?after.items.end():std::find_if(after.items.begin(),after.items.end(),[&](const Item& i){return i.id==old->id;});
|
||||
if(next==after.items.end())q={};else q.cell=next->cell;
|
||||
}
|
||||
result=plan;return true;
|
||||
}
|
||||
inline std::string Packet(const Frame& f){const auto body=Encode(f);if(body.empty())return {};Writer w;w.n(93,1);w.n(body.size()+5,4);return w.bytes+body;}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include <cerrno>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
namespace PortCube {
|
||||
class CraftEntropy {
|
||||
int fd=-1;
|
||||
public:
|
||||
CraftEntropy():fd(open("/dev/urandom",O_RDONLY|O_CLOEXEC)){}
|
||||
CraftEntropy(const CraftEntropy&)=delete;CraftEntropy& operator=(const CraftEntropy&)=delete;
|
||||
~CraftEntropy(){if(fd>=0)close(fd);}
|
||||
unsigned Draw() {
|
||||
if(fd<0)return 0;
|
||||
for(unsigned attempts=0;attempts<1024;++attempts) {
|
||||
unsigned char byte=0;ssize_t n;do{n=read(fd,&byte,1);}while(n<0&&errno==EINTR);
|
||||
if(n!=1)return 0;if(byte<200)return unsigned(byte)%100+1; // unbiased two samples per outcome
|
||||
}
|
||||
return 0; // no deterministic fallback or unbounded source failure loop
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include "cube_batch.h"
|
||||
namespace PortCube {
|
||||
struct CraftReceipt {std::string result;unsigned successes=0;uint64_t fee=0;std::vector<Item> awards;};
|
||||
inline unsigned CraftCode(const std::string& name) {
|
||||
const std::vector<std::string> names={"ok","gold_changed","inventory_changed","materials_missing","gold_missing","capacity_full","item_proto","inventory_invalid"};
|
||||
const auto found=std::find(names.begin(),names.end(),name);return found==names.end()?0:unsigned(found-names.begin())+1;
|
||||
}
|
||||
inline std::string EncodeCraftReceipt(const CraftReceipt& receipt) {
|
||||
const auto code=CraftCode(receipt.result);
|
||||
if(!code||receipt.successes>100||receipt.fee>uint64_t(PortEconomy::GoldLimit)||receipt.awards.size()>100||
|
||||
(code!=1&&(receipt.successes||receipt.fee||!receipt.awards.empty())))return {};
|
||||
std::set<uint32_t> ids;std::set<uint16_t> cells;
|
||||
for(const auto& item:receipt.awards)if(!item.value.id||!item.value.vnum||!item.value.count||item.value.count>2000||!item.usable||item.cell>=225||!ids.insert(item.value.id).second||!cells.insert(item.cell).second)return {};
|
||||
Writer w;w.data="CCR1";w.n(code,1);w.n(receipt.successes,1);w.n(receipt.fee,8);w.items(receipt.awards);return w.data;
|
||||
}
|
||||
inline bool DecodeCraftReceipt(const std::string& bytes,CraftReceipt& out) {
|
||||
out={};if(bytes.size()<16||bytes.size()>11716||bytes.substr(0,4)!="CCR1")return false;Reader r(bytes);r.at=4;
|
||||
const auto code=r.n(1);const std::vector<std::string> names={"ok","gold_changed","inventory_changed","materials_missing","gold_missing","capacity_full","item_proto","inventory_invalid"};
|
||||
if(!code||code>names.size())return false;CraftReceipt receipt;receipt.result=names[size_t(code)-1];receipt.successes=unsigned(r.n(1));receipt.fee=r.n(8);receipt.awards=r.items();
|
||||
if(!r.ok||r.at!=bytes.size()||EncodeCraftReceipt(receipt)!=bytes)return false;out=std::move(receipt);return true;
|
||||
}
|
||||
inline bool ValidateCraftReceipt(const Batch& b,const CraftReceipt& receipt,const Lookup& lookup) {
|
||||
if(!Validate(b)||EncodeCraftReceipt(receipt).empty())return false;if(receipt.result!="ok")return true;
|
||||
if(receipt.successes>b.attempts||(!b.recipe.percent&&receipt.successes)||(b.recipe.percent==100&&receipt.successes!=b.attempts))return false;
|
||||
std::string rolls(b.attempts,char(100));for(unsigned n=0;n<receipt.successes;++n)rolls[n]=char(1);
|
||||
const auto plan=SettlePlan(b,rolls,lookup);Writer actual,expected;actual.items(receipt.awards);expected.items(plan.awards);
|
||||
return plan.result=="ok"&&plan.successes==receipt.successes&&plan.fee==receipt.fee&&actual.data==expected.data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <iomanip>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// PORT: read-only normalization and consumption planning. No inventory mutation,
|
||||
// RNG, durable receipt, or implicit permission to craft lives in this layer.
|
||||
namespace PortCube {
|
||||
constexpr unsigned MaxAttempts=100,MaxRecipes=4096;
|
||||
struct Material {uint32_t vnum=0,count=0;};
|
||||
struct Recipe {
|
||||
uint32_t id=0,reward=0,rewardCount=0,gold=0;
|
||||
unsigned percent=0;bool stackable=false,copy=false;
|
||||
std::string category="WORLDARD";
|
||||
std::vector<uint32_t> npcs;
|
||||
std::vector<Material> materials;
|
||||
};
|
||||
inline bool Normalize(Recipe& r) {
|
||||
if(!r.id||!r.reward||!r.rewardCount||r.rewardCount>2000||(!r.stackable&&r.rewardCount!=1)||
|
||||
r.percent>100||r.npcs.empty()||r.npcs.size()>128||r.materials.empty()||r.materials.size()>5||
|
||||
r.category.empty()||r.category.size()>24)return false;
|
||||
for(char c:r.category)if(!((c>='a'&&c<='z')||(c>='A'&&c<='Z')||(c>='0'&&c<='9')||c=='_'))return false;
|
||||
for(auto npc:r.npcs)if(!npc||npc>65535)return false;
|
||||
std::sort(r.npcs.begin(),r.npcs.end());r.npcs.erase(std::unique(r.npcs.begin(),r.npcs.end()),r.npcs.end());
|
||||
std::vector<Material> merged;
|
||||
for(auto m:r.materials) {
|
||||
if(!m.vnum||!m.count||m.count>2000)return false;
|
||||
auto it=std::find_if(merged.begin(),merged.end(),[&](const Material& a){return a.vnum==m.vnum;});
|
||||
if(it==merged.end())merged.push_back(m);
|
||||
else {if(it->count>2000-m.count)return false;it->count+=m.count;}
|
||||
}
|
||||
r.materials=merged;return true;
|
||||
}
|
||||
inline std::string Fingerprint(const std::string& text) {
|
||||
uint64_t hash=14695981039346656037ULL;
|
||||
for(unsigned char c:text){hash^=c;hash*=1099511628211ULL;}
|
||||
std::ostringstream s;s<<std::hex<<std::setw(16)<<std::setfill('0')<<hash;return s.str();
|
||||
}
|
||||
inline std::string Revision(const Recipe& r) {
|
||||
std::ostringstream s;s<<r.id<<':'<<r.reward<<':'<<r.rewardCount<<':'<<r.gold<<':'<<r.percent<<':'<<r.stackable<<':'<<r.copy<<':'<<r.category;
|
||||
for(auto n:r.npcs)s<<":n"<<n;
|
||||
for(auto m:r.materials)s<<":m"<<m.vnum<<','<<m.count;
|
||||
return Fingerprint(s.str()); // staleness fingerprint, not a cryptographic authorization token
|
||||
}
|
||||
struct Input {uint32_t id=0,vnum=0,count=0;uint16_t cell=0;bool usable=true;};
|
||||
struct Take {uint32_t id=0,vnum=0,count=0,before=0;uint16_t cell=0;};
|
||||
struct Plan {
|
||||
bool valid=false,materialsOK=false,goldOK=false;
|
||||
uint64_t gold=0,rewardMaximum=0;
|
||||
std::vector<uint64_t> needed,available;
|
||||
std::vector<Take> takes;
|
||||
};
|
||||
inline Plan Preview(Recipe recipe,unsigned attempts,std::vector<Input> inputs,int64_t gold) {
|
||||
Plan p;if(!Normalize(recipe)||!attempts||attempts>MaxAttempts||gold<0||inputs.size()>225)return p;
|
||||
std::set<uint32_t> ids;std::set<uint16_t> cells;
|
||||
for(auto i:inputs)if(!i.id||!i.vnum||!i.count||i.count>2000||i.cell>=225||!ids.insert(i.id).second||!cells.insert(i.cell).second)return p;
|
||||
std::sort(inputs.begin(),inputs.end(),[](const Input& a,const Input& b){return a.cell<b.cell;});
|
||||
p.gold=uint64_t(recipe.gold)*attempts;p.rewardMaximum=uint64_t(recipe.rewardCount)*attempts;
|
||||
p.goldOK=uint64_t(gold)>=p.gold;p.materialsOK=true;
|
||||
for(auto m:recipe.materials) {
|
||||
const uint64_t need=uint64_t(m.count)*attempts;uint64_t available=0,left=need;
|
||||
for(auto i:inputs)if(i.usable&&i.vnum==m.vnum) {
|
||||
available+=i.count;const auto count=static_cast<uint32_t>(std::min(left,uint64_t(i.count)));
|
||||
if(count)p.takes.push_back({i.id,i.vnum,count,i.count,i.cell});left-=count;
|
||||
}
|
||||
p.needed.push_back(need);p.available.push_back(available);p.materialsOK&=available>=need;
|
||||
}
|
||||
p.valid=true;return p;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
#include "cube_handshake.h"
|
||||
namespace PortCube {
|
||||
inline Handshake RecoveryRequest(uint32_t account,uint32_t player,uint64_t session) {
|
||||
Handshake f;f.message=Message::RecoveryClaim;f.account=account;f.player=player;f.session=session;f.owner=f.token=std::string(32,'0');return f;
|
||||
}
|
||||
// This pre-load coordinator never grants actor action permission. Clear only
|
||||
// authorizes a normal load request, whose DB guards must still run again.
|
||||
class RecoveryFlow {
|
||||
public:
|
||||
enum Stage {Idle,Waiting,Held,Granted,Clear,Loading,ImageReady};
|
||||
private:
|
||||
Handshake request;OwnerGrant grant;Stage stage=Idle;bool lost=false;std::string image;
|
||||
public:
|
||||
Stage State()const{return stage;}
|
||||
const OwnerGrant& Grant()const{return grant;}
|
||||
const Handshake& Request()const{return request;}
|
||||
const std::string& Image()const{return image;}
|
||||
bool MayRequestImage()const{return !lost&&stage==Granted;}
|
||||
Handshake ImageRequest()const {
|
||||
Handshake f=request;f.message=Message::RecoveryImageRequest;const auto& b=grant.binding;
|
||||
f.cookie=b.cookie;f.epoch=b.epoch;f.owner=b.owner;f.token=b.request;f.body=EncodeOwnerGrant(grant);return f;
|
||||
}
|
||||
bool Start(uint32_t account,uint32_t player,uint64_t session) {
|
||||
auto f=RecoveryRequest(account,player,session);if(stage!=Idle||!ValidHandshake(f))return false;request=std::move(f);stage=Waiting;return true;
|
||||
}
|
||||
bool MayRetry()const{return !lost&&(stage==Waiting||stage==Held);}
|
||||
void LostTransport(){if(stage!=Idle){lost=true;stage=Held;image.clear();}}
|
||||
bool Answer(uint32_t handle,const Handshake& f) {
|
||||
if(lost||stage==Idle||stage==Loading||!ValidHandshake(f)||f.account!=request.account||f.player!=request.player||f.session!=request.session)return false;
|
||||
if(f.message==Message::RecoveryImageAnswer) {
|
||||
if(stage!=Granted&&stage!=ImageReady)return false;
|
||||
OwnerGrant g;std::string data;
|
||||
if(f.status==Status::Held){return stage==Granted&&DecodeOwnerGrant(f.body,g)&&g.binding.handle==handle&&SameOwnerGrant(g,grant);}
|
||||
if(!DecodeRecoveryImage(f.body,g,data)||g.binding.handle!=handle||!SameOwnerGrant(g,grant))return false;
|
||||
if(stage==ImageReady){if(data==image)return true;LostTransport();return false;}
|
||||
image=std::move(data);stage=ImageReady;return true;
|
||||
}
|
||||
if(f.message!=Message::RecoveryAnswer)return false;
|
||||
if(f.status==Status::RecoveryGranted) {
|
||||
OwnerGrant g;if(!DecodeOwnerGrant(f.body,g)||g.binding.handle!=handle)return false;
|
||||
if(stage==Granted||stage==ImageReady)return SameOwnerGrant(g,grant);
|
||||
if(stage==Clear)return false;grant=std::move(g);stage=Granted;return true;
|
||||
}
|
||||
if(stage==Granted||stage==Clear||stage==ImageReady)return false;
|
||||
stage=f.status==Status::RecoveryClear?Clear:Held;return true;
|
||||
}
|
||||
bool TakeClear(){if(lost||stage!=Clear)return false;stage=Loading;return true;}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
#include "cube_image_ack.h"
|
||||
namespace PortCube {
|
||||
template<class DB> bool ReleaseSchema(DB& db) {
|
||||
PortEconomy::Rows rows;const std::string names="('port_cube_release_version','port_cube_releases')";
|
||||
auto q=[&](const std::string& sql){return db.Query(sql,rows)&&!db.warnings&&rows.size()==1&&rows[0].size()==1;};
|
||||
return q("SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN "+names)&&rows[0][0]=="2"&&
|
||||
q("SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA=DATABASE() AND ENGINE='InnoDB' AND TABLE_NAME IN "+names)&&rows[0][0]=="2"&&
|
||||
q("SELECT version FROM port_cube_release_version WHERE id=1")&&rows[0][0]=="1";
|
||||
}
|
||||
// Terminal SQL decision, NOT actor readiness or permission to thaw. The runtime
|
||||
// keeps its save/load gate until an independently verified resume handoff.
|
||||
template<class DB> class ReleaseStore {
|
||||
DB& db;Lookup lookup;
|
||||
static std::string X(const std::string& s){return "X'"+PortEconomy::Hex(s.data(),s.size())+"'";}
|
||||
public:
|
||||
enum Result {Retry,Refused,Released};
|
||||
ReleaseStore(DB& d,Lookup p):db(d),lookup(std::move(p)){}
|
||||
enum CheckResult {CheckRetry,CheckRefused,Checked};
|
||||
CheckResult CheckResumeLive(const Batch& b,const OwnerGrant& grant,const std::string& image) {
|
||||
InventoryImage decoded;
|
||||
if(!Validate(b)||!Valid(grant)||!Matches(grant.binding,b)||!DecodeInventoryImage(image,decoded,lookup))return CheckRefused;
|
||||
if(!ImageAckSchema(db)||!ReleaseSchema(db))return CheckRetry;
|
||||
OwnerStore<DB> owner(db,lookup);FenceStore<DB> fence(db,lookup);
|
||||
const auto result=fence.CheckReleasedImage(b,image,[&]()->bool{
|
||||
PortEconomy::Rows rows;const std::vector<std::string> exact={Encode(b),EncodeOwnerGrant(grant),image};
|
||||
auto q=[&](const std::string& sql){return db.Query(sql,rows)&&!db.warnings;};
|
||||
if(!q("SELECT body,owner_grant,image FROM port_cube_image_acks WHERE request='"+b.token+"' FOR UPDATE")||rows.size()!=1||rows[0]!=exact)return false;
|
||||
if(!q("SELECT body,owner_grant,image FROM port_cube_releases WHERE request='"+b.token+"' FOR UPDATE")||rows.size()!=1||rows[0]!=exact)return false;
|
||||
if(!q("SELECT id FROM port_cube_item_fences WHERE pid="+std::to_string(b.player)+" OR request='"+b.token+"' FOR UPDATE")||!rows.empty())return false;
|
||||
return owner.ReleasedImageWithin(b,grant,image);
|
||||
});
|
||||
return result==FenceStore<DB>::Done?Checked:result==FenceStore<DB>::Retry?CheckRetry:CheckRefused;
|
||||
}
|
||||
Result ReleaseLive(const Batch& b,const OwnerGrant& grant,const std::string& image) {
|
||||
InventoryImage decoded;
|
||||
if(!Validate(b)||!Valid(grant)||!Matches(grant.binding,b)||!DecodeInventoryImage(image,decoded,lookup))return Refused;
|
||||
if(!ImageAckSchema(db)||!ReleaseSchema(db))return Retry;
|
||||
OwnerStore<DB> owner(db,lookup);FenceStore<DB> fence(db,lookup);
|
||||
const auto result=fence.Release(b,image,[&](bool replay)->bool {
|
||||
PortEconomy::Rows rows;auto q=[&](const std::string& sql){return db.Query(sql,rows)&&!db.warnings;};
|
||||
const std::vector<std::string> exact={Encode(b),EncodeOwnerGrant(grant),image};
|
||||
if(!q("SELECT body,owner_grant,image FROM port_cube_image_acks WHERE request='"+b.token+"' FOR UPDATE")||rows.size()!=1||rows[0]!=exact)return false;
|
||||
if(replay&&!owner.ReleasedWithin(b,grant))return false;
|
||||
if(!replay&&!owner.LiveImageWithin(b,grant,image))return false;
|
||||
if(!replay&&(!q("SELECT id FROM port_cube_item_fences WHERE request='"+b.token+"' AND pid<>"+std::to_string(b.player)+" FOR UPDATE")||!rows.empty()))return false;
|
||||
if(!q("SELECT body,owner_grant,image FROM port_cube_releases WHERE request='"+b.token+"' FOR UPDATE"))return false;
|
||||
if(replay) {
|
||||
if(rows.size()!=1||rows[0]!=exact)return false;
|
||||
// A terminal replay cannot bless a partially removed fence.
|
||||
return q("SELECT id FROM port_cube_item_fences WHERE pid="+std::to_string(b.player)+" OR request='"+b.token+"' FOR UPDATE")&&rows.empty();
|
||||
}
|
||||
if(!rows.empty())return false; // terminal history with LIVE lease is inconsistent
|
||||
if(!q("INSERT INTO port_cube_releases(request,body,owner_grant,image) VALUES('"+b.token+"',"+X(exact[0])+","+X(exact[1])+","+X(image)+")")||db.affected!=1)return false;
|
||||
return q("DELETE FROM port_cube_owner_leases WHERE request='"+b.token+"' AND phase='LIVE' AND revision="+std::to_string(grant.revision))&&db.affected==1;
|
||||
});
|
||||
return result==FenceStore<DB>::Done?Released:result==FenceStore<DB>::Retry?Retry:Refused;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
#pragma once
|
||||
#include "cube_batch.h"
|
||||
#include "economy_store.h"
|
||||
|
||||
namespace PortCube {
|
||||
// Candidate DB transaction engine. Nothing calls it from the live game yet.
|
||||
// Shared economy ID tombstones ensure prepared factory IDs cannot be recycled
|
||||
// by the existing DB restart high-water algorithm, even after a rejected batch.
|
||||
template<class DB> class BatchStore {
|
||||
DB& db;Lookup lookup;
|
||||
using Rows=PortEconomy::Rows;
|
||||
static std::string N(uint64_t value){return std::to_string(value);}
|
||||
// Silent truncation is an error even on a non-strict MySQL connection.
|
||||
bool Q(const std::string& sql,Rows& rows){return db.Query(sql,rows)&&db.warnings==0;}
|
||||
bool Run(const std::string& sql){Rows rows;return Q(sql,rows);}
|
||||
bool Change(const std::string& sql){return Run(sql)&&db.affected==1;}
|
||||
bool One(const std::string& sql,Rows& rows){return Q(sql,rows)&&rows.size()==1;}
|
||||
struct Guard {DB& db;~Guard(){db.Rollback();}};
|
||||
bool LockAccount(uint32_t account){Rows rows;return Run("INSERT INTO port_economy_account_lock(account) VALUES("+N(account)+") ON DUPLICATE KEY UPDATE account=VALUES(account)")&&One("SELECT account FROM port_economy_account_lock WHERE account="+N(account)+" FOR UPDATE",rows);}
|
||||
int Fence(const Batch& b) {
|
||||
Rows rows;
|
||||
if(!Q("SELECT epoch,owner,request,phase,body,drain_state FROM port_cube_fences WHERE pid="+N(b.player)+" AND account="+N(b.account)+" FOR UPDATE",rows))return -1;
|
||||
if(rows.size()!=1||rows[0].size()!=6||rows[0][0]!=N(b.epoch)||rows[0][1]!=b.owner||rows[0][2]!=b.token||rows[0][3]!="FROZEN"||rows[0][4]!=Encode(b)||rows[0][5]!="1")return 0;
|
||||
if(!Q("SELECT id,epoch,request FROM port_cube_item_fences WHERE pid="+N(b.player)+" FOR UPDATE",rows))return -1;
|
||||
std::set<uint32_t> locked;
|
||||
for(const auto& row:rows){uint64_t id=0;if(row.size()!=3||!PortEconomy::Number(row[0],id,UINT32_MAX)||!id||row[1]!=N(b.epoch)||row[2]!=b.token||!locked.insert(uint32_t(id)).second)return 0;}
|
||||
for(const auto& item:b.inventory)if(!locked.count(item.value.id))return 0;
|
||||
for(const auto& item:b.rewards)if(!locked.count(item.id))return 0;
|
||||
if(!Q("SELECT token FROM port_economy_pending WHERE pid="+N(b.player)+" FOR UPDATE",rows))return -1;
|
||||
return rows.empty()?1:0;
|
||||
}
|
||||
static std::string Columns() {
|
||||
std::string s="id,vnum,count,pos";
|
||||
for(unsigned i=0;i<3;++i)s+=",socket"+N(i);
|
||||
for(unsigned i=0;i<7;++i)s+=",attrtype"+N(i)+",attrvalue"+N(i);
|
||||
return s+",port_extra";
|
||||
}
|
||||
static std::vector<std::string> ItemRow(const Item& i) {
|
||||
const auto& item=i.value;std::vector<std::string> row={N(item.id),N(item.vnum),N(item.count),N(i.cell)};
|
||||
for(auto socket:item.sockets)row.push_back(std::to_string(socket));
|
||||
for(unsigned n=0;n<7;++n){row.push_back(N(item.types[n]));row.push_back(std::to_string(item.values[n]));}
|
||||
row.emplace_back(reinterpret_cast<const char*>(item.extra),sizeof(item.extra));return row;
|
||||
}
|
||||
bool Inventory(const Batch& b,bool& matches) {
|
||||
Rows rows;if(!Q("SELECT "+Columns()+" FROM item WHERE owner_id="+N(b.player)+" AND window='INVENTORY' AND pos<225 ORDER BY pos,id FOR UPDATE",rows))return false;
|
||||
matches=rows.size()==b.inventory.size();
|
||||
for(unsigned i=0;matches&&i<rows.size();++i)matches=rows[i]==ItemRow(b.inventory[i]);
|
||||
return true;
|
||||
}
|
||||
bool Insert(uint32_t player,const Item& i) {
|
||||
const auto row=ItemRow(i);std::string values;
|
||||
for(unsigned n=0;n+1<row.size();++n){if(n)values+=',';values+=row[n];}
|
||||
values+=",X'"+PortEconomy::Hex(row.back().data(),row.back().size())+"'";
|
||||
return Change("INSERT INTO item("+Columns()+",owner_id,window) VALUES("+values+","+N(player)+",'INVENTORY')");
|
||||
}
|
||||
public:
|
||||
enum Result { Retry, Rejected, Prepared, Complete, Blocked };
|
||||
struct Receipt {std::string result;unsigned successes=0;uint64_t fee=0;std::vector<Item> awards;};
|
||||
BatchStore(DB& database,Lookup proto):db(database),lookup(std::move(proto)){}
|
||||
// Read-only validation shared with deferred-credit recovery. Never execute
|
||||
// PREPARED just to inspect a receipt; callers must hold the account lock.
|
||||
static bool DoneReceipt(const Batch& b,const std::vector<std::string>& saved,Receipt& receipt) {
|
||||
receipt={};if(!Validate(b)||saved.size()!=7||saved[0]!=Encode(b)||saved[2]!="DONE")return false;
|
||||
uint64_t successes=0,fee=0;Reader r(saved[6]);auto awards=r.items();
|
||||
if(!PortEconomy::Number(saved[4],successes,b.attempts)||!PortEconomy::Number(saved[5],fee,PortEconomy::GoldLimit)||!r.ok||r.at!=saved[6].size())return false;
|
||||
const std::set<std::string> results={"ok","gold_changed","inventory_changed","materials_missing","gold_missing","capacity_full","item_proto","inventory_invalid"};
|
||||
if(!results.count(saved[3])||saved[1].size()!=b.attempts)return false;
|
||||
unsigned rolled=0;for(unsigned char roll:saved[1]){if(roll<1||roll>100)return false;rolled+=roll<=b.recipe.percent;}
|
||||
if(saved[3]!="ok") {if(successes||fee||!awards.empty())return false;}
|
||||
else {
|
||||
if(successes!=rolled||fee!=uint64_t(b.recipe.gold)*b.attempts||fee>b.gold)return false;
|
||||
uint64_t remaining=successes*b.recipe.rewardCount;std::set<unsigned> cells;
|
||||
if(awards.size()>b.rewards.size())return false;
|
||||
for(unsigned n=0;n<awards.size();++n) {
|
||||
if(!remaining||awards[n].cell>=225||!awards[n].usable||!cells.insert(awards[n].cell).second)return false;
|
||||
auto expected=b.rewards[n];expected.count=uint32_t(std::min(remaining,uint64_t(b.recipe.stackable?2000:1)));
|
||||
Writer actual,image;actual.reward(awards[n].value);image.reward(expected);
|
||||
if(actual.data!=image.data)return false;remaining-=expected.count;
|
||||
}
|
||||
if(remaining)return false;
|
||||
}
|
||||
receipt={saved[3],unsigned(successes),fee,std::move(awards)};return true;
|
||||
}
|
||||
bool Ready() {
|
||||
Rows rows;
|
||||
if(!One("SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA=DATABASE() AND ENGINE='InnoDB' AND TABLE_NAME IN ('player','item','port_cube_version','port_cube_requests','port_cube_fences','port_cube_item_fences','port_economy_account_lock','port_economy_item_reservations','port_economy_custody','port_economy_pending','port_economy_version')",rows)||rows[0][0]!="11"||
|
||||
!One("SELECT version FROM port_cube_version WHERE id=1",rows)||rows[0][0]!="2"||
|
||||
!One("SELECT version FROM port_economy_version WHERE id=1",rows)||rows[0][0]!="1")return false;
|
||||
// Do not silently discard a future item column. All item state must be
|
||||
// covered by both the snapshot comparison and the reward factory image.
|
||||
if(!Q("SHOW COLUMNS FROM item",rows))return false;
|
||||
std::set<std::string> expected={"id","owner_id","window","pos","count","vnum","port_extra"};
|
||||
for(unsigned i=0;i<3;++i)expected.insert("socket"+N(i));
|
||||
for(unsigned i=0;i<7;++i){expected.insert("attrtype"+N(i));expected.insert("attrvalue"+N(i));}
|
||||
for(const auto& row:rows) {
|
||||
if(row.empty()||!expected.erase(row[0]))return false;
|
||||
if(row[0]=="port_extra"&&(row.size()<3||(row[1]!="varbinary(69)"&&row[1]!="binary(69)")||row[2]!="NO"))return false;
|
||||
}
|
||||
return expected.empty();
|
||||
}
|
||||
// Draw callback is DB-side trusted RNG, called ONLY for a newly accepted
|
||||
// identity. Every draw is durable before any asset mutation is attempted.
|
||||
Result Prepare(const Batch& b,const std::function<unsigned()>& draw,const std::function<bool()>& authorize={}) {
|
||||
if(!Validate(b))return Rejected;
|
||||
if(!Ready()||!db.Begin())return Retry;
|
||||
Guard guard{db};
|
||||
Rows rows;const auto body=Encode(b);
|
||||
auto stop=[](Result result){return result;};
|
||||
if(!LockAccount(b.account))return stop(Retry);
|
||||
if(authorize&&!authorize())return stop(Blocked);
|
||||
if(!Q("SELECT body,state FROM port_cube_requests WHERE token='"+b.token+"' FOR UPDATE",rows))return stop(Retry);
|
||||
if(!rows.empty()) {
|
||||
if(rows.size()!=1||rows[0].size()!=2||rows[0][0]!=body||(rows[0][1]!="PREPARED"&&rows[0][1]!="DONE"))return stop(Rejected);
|
||||
// Even DONE requests replay without drawing or touching assets.
|
||||
return stop(Prepared);
|
||||
}
|
||||
const int fence=Fence(b);if(fence<=0)return stop(fence<0?Retry:Blocked);
|
||||
for(const auto& reward:b.rewards) {
|
||||
if(!Q("SELECT id FROM item WHERE id="+N(reward.id)+" UNION ALL SELECT id FROM port_economy_custody WHERE id="+N(reward.id),rows))return stop(Retry);
|
||||
if(!rows.empty())return stop(Rejected);
|
||||
if(!Q("SELECT request FROM port_economy_item_reservations WHERE id="+N(reward.id)+" FOR UPDATE",rows))return stop(Retry);
|
||||
if(rows.empty()) {if(!Change("INSERT INTO port_economy_item_reservations(id,request) VALUES("+N(reward.id)+",'"+b.token+"')"))return stop(Retry);}
|
||||
else if(rows.size()!=1||rows[0].size()!=1||rows[0][0]!=b.token)return stop(Rejected);
|
||||
}
|
||||
std::string rolls;for(unsigned i=0;i<b.attempts;++i){const auto roll=draw();if(roll<1||roll>100)return stop(Rejected);rolls+=char(roll);}
|
||||
if(!Change("INSERT INTO port_cube_requests(token,account,pid,body,rolls,state,result,successes,fee,awards) VALUES('"+b.token+"',"+N(b.account)+","+N(b.player)+",X'"+PortEconomy::Hex(body.data(),body.size())+"',X'"+PortEconomy::Hex(rolls.data(),rolls.size())+"','PREPARED','prepared',0,0,X'0000')")||!db.Commit())return stop(Retry);
|
||||
return Prepared;
|
||||
}
|
||||
// Identity-only recovery loads the complete immutable request and fixed RNG
|
||||
// from storage. A disconnected caller cannot supply a replacement snapshot.
|
||||
Result Execute(const std::string& token,uint32_t account,uint32_t player,Receipt& receipt,const std::function<bool(const Batch&)>& authorize={}) {
|
||||
receipt={};if(!Identity(token)||!account||!player)return Rejected;
|
||||
if(!Ready()||!db.Begin())return Retry;
|
||||
Guard guard{db};
|
||||
auto stop=[](Result result){return result;};Rows rows;
|
||||
if(!LockAccount(account)||!Q("SELECT body,rolls,state,result,successes,fee,awards FROM port_cube_requests WHERE token='"+token+"' AND account="+N(account)+" AND pid="+N(player)+" FOR UPDATE",rows))return stop(Retry);
|
||||
if(rows.empty())return stop(Rejected);
|
||||
if(rows.size()!=1||rows[0].size()!=7)return stop(Retry);
|
||||
const auto saved=rows[0];Batch b;uint64_t fee=0;
|
||||
if(!Decode(saved[0],b)||b.token!=token||b.account!=account||b.player!=player)return stop(Retry);
|
||||
if(authorize&&!authorize(b))return stop(Blocked);
|
||||
if(saved[2]=="DONE") {
|
||||
return stop(DoneReceipt(b,saved,receipt)?Complete:Retry);
|
||||
}
|
||||
if(saved[2]!="PREPARED")return stop(Retry);
|
||||
const int fence=Fence(b);if(fence<=0)return stop(fence<0?Retry:Blocked);
|
||||
if(!One("SELECT gold FROM player WHERE id="+N(player)+" AND account_id="+N(account)+" FOR UPDATE",rows)||rows[0].size()!=1||!PortEconomy::Number(rows[0][0],fee,PortEconomy::GoldLimit))return stop(Retry);
|
||||
Settlement plan;
|
||||
if(fee!=b.gold)plan.result="gold_changed";
|
||||
else {
|
||||
bool matches=false;if(!Inventory(b,matches))return stop(Retry);
|
||||
if(!matches)plan.result="inventory_changed";
|
||||
else plan=SettlePlan(b,saved[1],lookup);
|
||||
}
|
||||
if(plan.result=="invalid")return stop(Retry); // corrupt persisted input: quarantine, never charge
|
||||
if(plan.result=="ok") {
|
||||
for(const auto& take:plan.takes) {
|
||||
const std::string where=" WHERE id="+N(take.id)+" AND owner_id="+N(player)+" AND window='INVENTORY' AND count="+N(take.before);
|
||||
if(!Change(take.count==take.before?"DELETE FROM item"+where:"UPDATE item SET count=count-"+N(take.count)+where))return stop(Retry);
|
||||
}
|
||||
if(plan.fee&&!Change("UPDATE player SET gold=gold-"+N(plan.fee)+" WHERE id="+N(player)+" AND account_id="+N(account)+" AND gold="+N(b.gold)))return stop(Retry);
|
||||
for(const auto& award:plan.awards)if(!Insert(player,award))return stop(Retry);
|
||||
} else {plan.successes=0;plan.fee=0;plan.awards.clear();}
|
||||
Writer awards;awards.items(plan.awards);
|
||||
if(!Change("UPDATE port_cube_requests SET state='DONE',result='"+plan.result+"',successes="+N(plan.successes)+",fee="+N(plan.fee)+",awards=X'"+PortEconomy::Hex(awards.data.data(),awards.data.size())+"' WHERE token='"+token+"' AND state='PREPARED'")||!db.Commit())return stop(Retry);
|
||||
receipt={plan.result,plan.successes,plan.fee,std::move(plan.awards)};return Complete;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -13,7 +13,7 @@ class Mysql {
|
||||
unsigned previousTimeout=0;
|
||||
unsigned long thread=0;
|
||||
public:
|
||||
uint64_t affected=0,inserted=0;
|
||||
uint64_t affected=0,inserted=0,warnings=0;
|
||||
std::function<void(const std::string&)> afterStatement;
|
||||
explicit Mysql(MYSQL* handle):connection(handle) {
|
||||
// Reconnect only BEFORE entering the pinned transaction scope. Without
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
}
|
||||
~Mysql(){Rollback();if(previousTimeout){Rows rows;Query("SET SESSION innodb_lock_wait_timeout="+std::to_string(previousTimeout),rows);}my_bool reconnect=true;mysql_options(connection,MYSQL_OPT_RECONNECT,&reconnect);}
|
||||
bool Query(const std::string& sql,Rows& rows) {
|
||||
rows.clear();affected=0;inserted=0;
|
||||
rows.clear();affected=0;inserted=0;warnings=0;
|
||||
if(!pinned || mysql_thread_id(connection)!=thread || mysql_real_query(connection,sql.data(),static_cast<unsigned long>(sql.size())))return false;
|
||||
MYSQL_RES* result=mysql_store_result(connection);
|
||||
if(result) {
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
}
|
||||
const bool ok=mysql_errno(connection)==0;mysql_free_result(result);if(!ok)return false;
|
||||
} else if(mysql_field_count(connection))return false;
|
||||
affected=mysql_affected_rows(connection);inserted=mysql_insert_id(connection);
|
||||
affected=mysql_affected_rows(connection);inserted=mysql_insert_id(connection);warnings=mysql_warning_count(connection);
|
||||
if(afterStatement)afterStatement(sql);
|
||||
return mysql_thread_id(connection)==thread;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ enum EItemMisc
|
||||
ITEM_LIMIT_MAX_NUM = 2,
|
||||
ITEM_APPLY_MAX_NUM = 3,
|
||||
ITEM_SOCKET_MAX_NUM = 3,
|
||||
ITEM_MAX_COUNT = 200,
|
||||
ITEM_MAX_COUNT = 2000,
|
||||
ITEM_ATTRIBUTE_MAX_NUM = 7,
|
||||
ITEM_ATTRIBUTE_MAX_LEVEL = 5,
|
||||
ITEM_AWARD_WHY_MAX_LEN = 50,
|
||||
@@ -99,6 +99,9 @@ enum EWeaponSubTypes
|
||||
WEAPON_FAN,
|
||||
WEAPON_ARROW,
|
||||
WEAPON_MOUNT_SPEAR,
|
||||
// PORT: preserve AVA2 numeric positions; reserving claw does not enable Wolfman.
|
||||
WEAPON_CLAW = 8,
|
||||
WEAPON_QUIVER = 9,
|
||||
WEAPON_NUM_TYPES,
|
||||
};
|
||||
|
||||
@@ -336,6 +339,9 @@ enum EItemAntiFlag
|
||||
ITEM_ANTIFLAG_STACK = (1 << 15), // í•©ì¹ ìˆ˜ ì—†ì�Œ
|
||||
ITEM_ANTIFLAG_MYSHOP = (1 << 16), // ê°œì�¸ ìƒ�ì �ì—� 올릴 수 ì—†ì�Œ
|
||||
ITEM_ANTIFLAG_SAFEBOX = (1 << 17), // ì°½ê³ ì—� ë„£ì�„ 수 ì—†ì�Œ
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
ITEM_ANTIFLAG_WOLFMAN = (1 << 18), // ¼öÀÎÁ· »ç¿ë ºÒ°¡
|
||||
#endif
|
||||
};
|
||||
|
||||
enum EItemWearableFlag
|
||||
|
||||
@@ -11,7 +11,11 @@ enum EMisc
|
||||
IP_ADDRESS_LENGTH = 15,
|
||||
LOGIN_MAX_LEN = 30,
|
||||
PASSWD_MAX_LEN = 16,
|
||||
#ifdef ENABLE_PLAYER_PER_ACCOUNT5
|
||||
PLAYER_PER_ACCOUNT = 5,
|
||||
#else
|
||||
PLAYER_PER_ACCOUNT = 4,
|
||||
#endif
|
||||
ACCOUNT_STATUS_MAX_LEN = 8,
|
||||
CHARACTER_NAME_MAX_LEN = 24,
|
||||
#ifdef ENABLE_OFFLINESHOP_SYSTEM
|
||||
@@ -49,6 +53,9 @@ enum EMisc
|
||||
|
||||
PLAYER_EXP_TABLE_MAX = 120,
|
||||
PLAYER_MAX_LEVEL_CONST = 120,
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
PLAYER_MAX_CONQUEROR_LEVEL_CONST = 30,
|
||||
#endif
|
||||
|
||||
GUILD_MAX_LEVEL = 20,
|
||||
MOB_MAX_LEVEL = 100,
|
||||
@@ -235,6 +242,9 @@ enum EJobs
|
||||
JOB_ASSASSIN,
|
||||
JOB_SURA,
|
||||
JOB_SHAMAN,
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
JOB_WOLFMAN, // ¼öÀÎÁ·. °³¹ßÄÚµå¸íÀÌ WOLFMAN. (±âȹÀÚ°¡ Á¤Çß¾¸. ³ªÁß¿¡ WOLF GIRL »ý°Üµµ ³ªÇÑÅ× ¸Ó¶óÇÏÁö¸¶¼À¤Ð¤Ð)
|
||||
#endif
|
||||
JOB_MAX_NUM
|
||||
};
|
||||
|
||||
@@ -331,6 +341,16 @@ enum ECharacterPosition
|
||||
POSITION_MAX_NUM
|
||||
};
|
||||
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
enum EConquerorMap
|
||||
{
|
||||
EASTPLAIN_01 = 129,
|
||||
EASTPLAIN_02 = 130,
|
||||
EASTPLAIN_03 = 131,
|
||||
EMPIRECASTLE = 132,
|
||||
};
|
||||
#endif
|
||||
|
||||
enum EGMLevels
|
||||
{
|
||||
GM_PLAYER,
|
||||
@@ -481,18 +501,35 @@ enum EApplyTypes
|
||||
APPLY_ANTI_CRITICAL_PCT, //90 í�¬ë¦¬í‹°ì»¬ ì €í•
|
||||
APPLY_ANTI_PENETRATE_PCT, //91 관통타격 ì €í•
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
APPLY_BLEEDING_REDUCE = 92, //92
|
||||
APPLY_BLEEDING_PCT = 93, //93
|
||||
APPLY_ATTBONUS_WOLFMAN = 94, //94
|
||||
APPLY_RESIST_WOLFMAN = 95, //95
|
||||
APPLY_RESIST_CLAW = 96, //96
|
||||
#endif
|
||||
|
||||
|
||||
// PORT AVA2 bonus numbering (AVA2 common/length.h): 92-138 are AVA2 applies not ported yet,
|
||||
// kept free so later ports and the client item_proto keep AVA2's numbers.
|
||||
// AVA2 ELEMENT_NEW_BONUSES: attack bonus % against monsters of the element (RACE_FLAG_ATT_*), on the talismans.
|
||||
APPLY_RESIST_MAGIC_REDUCTION = 98, // AVA2 ENABLE_MAGIC_REDUCTION_SYSTEM.
|
||||
APPLY_RESIST_HUMAN = 99, // AVA2 growing-pet skill 17.
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
APPLY_SUNGMA_STR = 119,
|
||||
APPLY_SUNGMA_HP = 120,
|
||||
APPLY_SUNGMA_MOVE = 121,
|
||||
APPLY_SUNGMA_INMUNE = 122,
|
||||
#endif
|
||||
APPLY_ENCHANT_ELEC = 123,
|
||||
APPLY_ENCHANT_FIRE = 124,
|
||||
APPLY_ENCHANT_ICE = 125,
|
||||
APPLY_ENCHANT_WIND = 126,
|
||||
APPLY_ENCHANT_EARTH = 127,
|
||||
APPLY_ENCHANT_DARK = 128,
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
APPLY_ATTBONUS_CLAW = 138,
|
||||
#endif
|
||||
APPLY_ATTBONUS_STONE = 139,
|
||||
APPLY_ATTBONUS_BOSS = 140,
|
||||
|
||||
@@ -606,6 +643,9 @@ enum EMobEnchants
|
||||
MOB_ENCHANT_STUN,
|
||||
MOB_ENCHANT_CRITICAL,
|
||||
MOB_ENCHANT_PENETRATE,
|
||||
#if defined(ENABLE_WOLFMAN_CHARACTER) && !defined(USE_MOB_BLEEDING_AS_POISON)
|
||||
MOB_ENCHANT_BLEEDING,
|
||||
#endif
|
||||
MOB_ENCHANTS_MAX_NUM
|
||||
};
|
||||
|
||||
@@ -622,6 +662,12 @@ enum EMobResists
|
||||
MOB_RESIST_MAGIC,
|
||||
MOB_RESIST_WIND,
|
||||
MOB_RESIST_POISON,
|
||||
#if defined(ENABLE_WOLFMAN_CHARACTER) && !defined(USE_MOB_BLEEDING_AS_POISON)
|
||||
MOB_RESIST_BLEEDING,
|
||||
#endif
|
||||
#if defined(ENABLE_WOLFMAN_CHARACTER) && !defined(USE_MOB_CLAW_AS_DAGGER)
|
||||
MOB_RESIST_CLAW,
|
||||
#endif
|
||||
MOB_RESISTS_MAX_NUM
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,13 @@
|
||||
#define ENABLE_ATTR_6TH_7TH
|
||||
#define __BL_67_ATTR__
|
||||
#define ENABLE_SPECIAL_STORAGE
|
||||
#define ENABLE_WOLFMAN_CHARACTER
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
#define USE_MOB_BLEEDING_AS_POISON
|
||||
#define USE_MOB_CLAW_AS_DAGGER
|
||||
#endif
|
||||
#define ENABLE_CONQUEROR_LEVEL
|
||||
#define ENABLE_PLAYER_PER_ACCOUNT5
|
||||
#define UNLOCK_INVENTORY_WORLDARD
|
||||
#define ENABLE_OFFLINESHOP_SYSTEM
|
||||
#ifdef ENABLE_OFFLINESHOP_SYSTEM
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <deque>
|
||||
#include <map>
|
||||
|
||||
// DB-main-thread-only ownership router for results from the SAME player async
|
||||
// FIFO. SQL worker threads never access this registry. Tokens are opaque integers
|
||||
// in pvUserData, never pointers to an actor, ticket object or reclaimed memory.
|
||||
namespace PortSQLFence {
|
||||
enum Kind : unsigned { Economy=0, Cube=1 };
|
||||
template<class Message> class Router {
|
||||
struct Ticket {Kind kind;uint32_t logical;};
|
||||
uint32_t next=0,maximum;
|
||||
std::size_t capacity;
|
||||
uint64_t failures=0;
|
||||
std::map<uint32_t,Ticket> pending;
|
||||
std::array<std::deque<Message*>,2> ready;
|
||||
void Fault(){if(failures!=UINT64_MAX)++failures;}
|
||||
public:
|
||||
explicit Router(uint32_t maxToken=UINT32_MAX,std::size_t limit=8192):maximum(maxToken),capacity(limit){}
|
||||
~Router(){Clear();}
|
||||
Router(const Router&)=delete;Router& operator=(const Router&)=delete;
|
||||
uint32_t Reserve(Kind kind,uint32_t logical) {
|
||||
if(unsigned(kind)>1||!logical||next>=maximum||pending.size()+ready[0].size()+ready[1].size()>=capacity)return 0;
|
||||
const auto token=++next;pending.emplace(token,Ticket{kind,logical});return token;
|
||||
}
|
||||
bool Complete(Message* message) {
|
||||
if(!message){Fault();return false;}
|
||||
const auto raw=reinterpret_cast<uintptr_t>(message->pvUserData);
|
||||
auto it=raw<=UINT32_MAX?pending.find(uint32_t(raw)):pending.end();
|
||||
if(it==pending.end()){delete message;Fault();return false;}
|
||||
const auto ticket=it->second;pending.erase(it);
|
||||
message->pvUserData=reinterpret_cast<void*>(uintptr_t(ticket.logical));
|
||||
ready[unsigned(ticket.kind)].push_back(message);return true;
|
||||
}
|
||||
Message* Pop(Kind kind) {
|
||||
if(unsigned(kind)>1||ready[unsigned(kind)].empty())return nullptr;
|
||||
auto* message=ready[unsigned(kind)].front();ready[unsigned(kind)].pop_front();return message;
|
||||
}
|
||||
uint64_t Failures()const{return failures;}
|
||||
void Clear() {
|
||||
pending.clear();for(auto& queue:ready){for(auto* message:queue)delete message;queue.clear();}
|
||||
// Never recycle a token during this DB process, even on connection reset.
|
||||
Fault();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -367,6 +367,10 @@ typedef struct SSimplePlayer
|
||||
long lAddr;
|
||||
WORD wPort;
|
||||
BYTE skill_group;
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
BYTE byConquerorLevel;
|
||||
BYTE bySungmaST, bySungmaHP, bySungmaMove, bySungmaInmune;
|
||||
#endif
|
||||
} TSimplePlayer;
|
||||
|
||||
typedef struct SAccountTable
|
||||
@@ -494,6 +498,13 @@ typedef struct SPlayerTable
|
||||
DWORD logoff_interval;
|
||||
|
||||
int aiPremiumTimes[PREMIUM_MAX_NUM];
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
BYTE conquerorlevel;
|
||||
BYTE conqueror_level_step;
|
||||
short sungma_str, sungma_hp, sungma_move, sungma_inmune;
|
||||
DWORD conqueror_exp;
|
||||
short conqueror_point;
|
||||
#endif
|
||||
|
||||
#ifdef UNLOCK_INVENTORY_WORLDARD
|
||||
DWORD inventory_unlock[UNLOCK_INVENTORY_MAX];
|
||||
@@ -621,20 +632,20 @@ typedef struct SSkillTable
|
||||
typedef struct SShopItemTable
|
||||
{
|
||||
DWORD vnum;
|
||||
BYTE count;
|
||||
WORD count;
|
||||
|
||||
TItemPos pos; // PC 상점에만 이용
|
||||
int64_t price; // PC, shop_table_ex.txt 상점에만 이용
|
||||
BYTE display_pos; // PC, shop_table_ex.txt 상점에만 이용, 보일 위치.
|
||||
} TShopItemTable;
|
||||
static_assert(sizeof(TShopItemTable)==17,"gold64 private shop wire size");
|
||||
static_assert(sizeof(TShopItemTable)==18,"gold64 private shop wire size");
|
||||
|
||||
typedef struct SShopTable
|
||||
{
|
||||
DWORD dwVnum;
|
||||
DWORD dwNPCVnum;
|
||||
|
||||
BYTE byItemCount;
|
||||
WORD byItemCount;
|
||||
TShopItemTable items[SHOP_HOST_ITEM_MAX_NUM];
|
||||
} TShopTable;
|
||||
|
||||
|
||||
@@ -78,21 +78,30 @@ inline bool str_to_number (long long& out, const char *in)
|
||||
if(!in || !*in)return false;
|
||||
errno=0;char* end=NULL;const long long value=strtoll(in,&end,10);
|
||||
if(errno==ERANGE || end==in || *end)return false;
|
||||
out=value;return true;
|
||||
char* dst = reinterpret_cast<char*>(&out);
|
||||
const char* src = reinterpret_cast<const char*>(&value);
|
||||
for (size_t i = 0; i < sizeof(long long); ++i) dst[i] = src[i];
|
||||
return true;
|
||||
}
|
||||
inline bool str_to_number (unsigned long long& out, const char *in)
|
||||
{
|
||||
if(!in || !*in || ((*in<'0'||*in>'9')&&*in!='+'))return false;
|
||||
errno=0;char* end=NULL;const unsigned long long value=strtoull(in,&end,10);
|
||||
if(errno==ERANGE || end==in || *end)return false;
|
||||
out=value;return true;
|
||||
char* dst = reinterpret_cast<char*>(&out);
|
||||
const char* src = reinterpret_cast<const char*>(&value);
|
||||
for (size_t i = 0; i < sizeof(unsigned long long); ++i) dst[i] = src[i];
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool str_to_number (float& out, const char *in)
|
||||
{
|
||||
if (0==in || 0==in[0]) return false;
|
||||
|
||||
out = (float) strtof(in, NULL);
|
||||
float val = (float) strtof(in, NULL);
|
||||
char* dst = reinterpret_cast<char*>(&out);
|
||||
const char* src = reinterpret_cast<const char*>(&val);
|
||||
for (size_t i = 0; i < sizeof(float); ++i) dst[i] = src[i];
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -100,7 +109,10 @@ inline bool str_to_number (double& out, const char *in)
|
||||
{
|
||||
if (0==in || 0==in[0]) return false;
|
||||
|
||||
out = (double) strtod(in, NULL);
|
||||
double val = (double) strtod(in, NULL);
|
||||
char* dst = reinterpret_cast<char*>(&out);
|
||||
const char* src = reinterpret_cast<const char*>(&val);
|
||||
for (size_t i = 0; i < sizeof(double); ++i) dst[i] = src[i];
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1031,7 +1031,11 @@ void CClientManager::QUERY_EMPIRE_SELECT(CPeer * pkPeer, DWORD dwHandle, TEmpire
|
||||
sys_log(0, "EmpireSelect: %s", szQuery);
|
||||
{
|
||||
snprintf(szQuery, sizeof(szQuery),
|
||||
"SELECT pid1, pid2, pid3, pid4 FROM player_index%s WHERE id=%u", GetTablePostfix(), p->dwAccountID);
|
||||
"SELECT pid1, pid2, pid3, pid4"
|
||||
#ifdef ENABLE_PLAYER_PER_ACCOUNT5
|
||||
", pid5"
|
||||
#endif
|
||||
" FROM player_index%s WHERE id=%u", GetTablePostfix(), p->dwAccountID);
|
||||
|
||||
std::unique_ptr<SQLMsg> pmsg(CDBManager::instance().DirectQuery(szQuery));
|
||||
|
||||
@@ -1313,6 +1317,7 @@ void CClientManager::QUERY_SETUP(CPeer * peer, DWORD dwHandle, const char * c_pD
|
||||
void CClientManager::QUERY_ITEM_FLUSH(CPeer * pkPeer, const char * c_pData)
|
||||
{
|
||||
DWORD dwID = *(DWORD *) c_pData;
|
||||
if(!CubePeerMayWriteItem(pkPeer,dwID)||!CubeItemWritable(dwID))return; // PORT: bind ID-only flush to the held actor's peer
|
||||
|
||||
if (g_log)
|
||||
sys_log(0, "HEADER_GD_ITEM_FLUSH: %u", dwID);
|
||||
@@ -1326,7 +1331,7 @@ void CClientManager::QUERY_ITEM_FLUSH(CPeer * pkPeer, const char * c_pData)
|
||||
void CClientManager::QUERY_ITEM_SAVE(CPeer * pkPeer, const char * c_pData)
|
||||
{
|
||||
TPlayerItem * p = (TPlayerItem *) c_pData;
|
||||
if(!EconomyItemWritable(p->id))return;
|
||||
if(!CubePeerMayWriteItem(pkPeer,p->id)||!EconomyItemWritable(p->id))return;
|
||||
if(p->window!=SAFEBOX && p->window!=MALL && !EconomySaveAllowed(pkPeer,p->owner))return;
|
||||
|
||||
// 창고면 캐쉬하지 않고, 캐쉬에 있던 것도 빼버려야 한다.
|
||||
@@ -1638,7 +1643,7 @@ void CClientManager::QUERY_ITEM_DESTROY(CPeer * pkPeer, const char * c_pData)
|
||||
c_pData += sizeof(DWORD);
|
||||
|
||||
DWORD dwPID = *(DWORD *) c_pData;
|
||||
if(!EconomyItemWritable(dwID) || (dwPID && !EconomySaveAllowed(pkPeer,dwPID)))return;
|
||||
if(!CubePeerMayWriteItem(pkPeer,dwID) || !EconomyItemWritable(dwID) || (dwPID && !EconomySaveAllowed(pkPeer,dwPID)))return;
|
||||
|
||||
if (!DeleteItemCache(dwID))
|
||||
{
|
||||
@@ -1798,6 +1803,7 @@ void CClientManager::InsertLoginData(CLoginData * pkLD)
|
||||
|
||||
void CClientManager::DeleteLoginData(CLoginData * pkLD)
|
||||
{
|
||||
CubeAccountGone(pkLD->GetAccountRef().id,pkLD->GetConnectedPeerHandle()); // before auth replacement can reuse the same peer/account
|
||||
m_map_pkLoginData.erase(pkLD->GetKey());
|
||||
m_map_pkLoginDataByLogin.erase(pkLD->GetAccountRef().login);
|
||||
m_map_pkLoginDataByAID.erase(pkLD->GetAccountRef().id);
|
||||
@@ -2378,6 +2384,8 @@ void CClientManager::ProcessPackets(CPeer * peer)
|
||||
|
||||
switch (header)
|
||||
{
|
||||
case PortCube::HandshakeHeader:
|
||||
CubeHandshakeRequest(peer,dwHandle,data,dwLength);break;
|
||||
case 77:
|
||||
EconomyRequest(peer,dwHandle,data,dwLength);break;
|
||||
case 76:
|
||||
@@ -2395,6 +2403,7 @@ void CClientManager::ProcessPackets(CPeer * peer)
|
||||
|
||||
case HEADER_GD_LOGOUT:
|
||||
//sys_log(0, "HEADER_GD_LOGOUT (handle: %d length: %d)", dwHandle, dwLength);
|
||||
CubeAccountLogout(peer,data,dwLength); // mark before login removal/reuse; no synchronous SQL
|
||||
QUERY_LOGOUT(peer, dwHandle, data);
|
||||
break;
|
||||
|
||||
@@ -2859,6 +2868,7 @@ void CClientManager::AddPeer(socket_t fd)
|
||||
|
||||
void CClientManager::RemovePeer(CPeer * pPeer)
|
||||
{
|
||||
CubePeerGone(pPeer->GetHandle());
|
||||
if (m_pkAuthPeer == pPeer)
|
||||
{
|
||||
m_pkAuthPeer = NULL;
|
||||
@@ -2924,6 +2934,7 @@ int CClientManager::AnalyzeQueryResult(SQLMsg * msg)
|
||||
{
|
||||
CQueryInfo * qi = (CQueryInfo *) msg->pvUserData;
|
||||
if(qi->iType==QID_ECONOMY_FENCE) { EconomyMainFence(qi->dwIdent,msg->uiSQLErrno!=0);delete qi;return true; }
|
||||
if(qi->iType==PortCube::MainFirst||qi->iType==PortCube::MainSecond) { CubeMainFence(qi->dwIdent,qi->iType==PortCube::MainFirst?1:2,msg->uiSQLErrno!=0);delete qi;return true; }
|
||||
CPeer * peer = GetPeer(qi->dwIdent);
|
||||
|
||||
#ifdef _TEST
|
||||
@@ -3070,6 +3081,7 @@ int CClientManager::Process()
|
||||
{
|
||||
++thecore_heart->pulse;
|
||||
EconomyTick();
|
||||
CubeDrainTick();
|
||||
|
||||
/*
|
||||
//30분마다 변경
|
||||
@@ -4283,9 +4295,15 @@ void CClientManager::ChangeMonarchLord(CPeer * peer, DWORD dwHandle, TPacketChan
|
||||
char szQuery[1024];
|
||||
snprintf(szQuery, sizeof(szQuery),
|
||||
"SELECT a.name, NOW() FROM player%s AS a, player_index%s AS b WHERE (a.account_id=b.id AND a.id=%u AND b.empire=%u) AND "
|
||||
#ifdef ENABLE_PLAYER_PER_ACCOUNT5
|
||||
"(b.pid1=%u OR b.pid2=%u OR b.pid3=%u OR b.pid4=%u OR b.pid5=%u)",
|
||||
GetTablePostfix(), GetTablePostfix(), info->dwPID, info->bEmpire,
|
||||
info->dwPID, info->dwPID, info->dwPID, info->dwPID, info->dwPID);
|
||||
#else
|
||||
"(b.pid1=%u OR b.pid2=%u OR b.pid3=%u OR b.pid4=%u)",
|
||||
GetTablePostfix(), GetTablePostfix(), info->dwPID, info->bEmpire,
|
||||
info->dwPID, info->dwPID, info->dwPID, info->dwPID);
|
||||
#endif
|
||||
|
||||
SQLMsg * pMsg = CDBManager::instance().DirectQuery(szQuery, SQL_PLAYER);
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "Peer.h"
|
||||
#include "DBManager.h"
|
||||
#include "LoginData.h"
|
||||
#include "CubeRuntime.h"
|
||||
|
||||
class CPlayerTableCache;
|
||||
class CItemCache;
|
||||
@@ -30,11 +31,19 @@ size_t CreatePlayerSaveQuery(char * pszQuery, size_t querySize, TPlayerTable * p
|
||||
|
||||
class CClientManager : public CNetBase, public singleton<CClientManager>
|
||||
{
|
||||
struct EconomyFence { DWORD account=0; bool primed=false,mainDone=false,asyncDone=false,failed=false; uint64_t mainFailures=0,asyncFailures=0; time_t nextAttempt=0; DWORD peer=0,handle=0; TPlayerLoadPacket load={}; };
|
||||
struct EconomyFence { DWORD account=0; bool primed=false,mainDone=false,asyncDone=false,asyncQueued=false,failed=false; uint64_t mainFailures=0,asyncFailures=0,routerFailures=0; time_t nextAttempt=0; DWORD peer=0,handle=0; TPlayerLoadPacket load={}; };
|
||||
std::map<DWORD,std::pair<uint64_t,uint64_t>> m_economyEnqueueEpoch;
|
||||
std::map<DWORD,EconomyFence> m_economyFences;
|
||||
std::map<DWORD,DWORD> m_economyOwners;
|
||||
std::set<DWORD> m_economyClosed;
|
||||
DWORD m_cubeCookie=0;
|
||||
uint64_t m_cubeWorkCursor=0;
|
||||
std::map<DWORD,PortCube::RuntimeDrain> m_cubeDrains;
|
||||
std::string m_cubeOwnerBoot;
|
||||
bool CubeDrainOwner(const PortCube::RuntimeDrain&,bool=false);
|
||||
bool CubeAuthorityCheck(const PortCube::RuntimeDrain&,bool);
|
||||
void CubeAuthorityRevoke(PortCube::RuntimeDrain&,unsigned);
|
||||
void CubeDrainFinalize(PortCube::RuntimeDrain&);
|
||||
public:
|
||||
void EconomyRequest(CPeer*,DWORD,const char*,DWORD);
|
||||
bool EconomyBeforeLoad(CPeer*,DWORD,TPlayerLoadPacket*);
|
||||
@@ -43,6 +52,29 @@ class CClientManager : public CNetBase, public singleton<CClientManager>
|
||||
bool EconomySaveAllowed(CPeer*,DWORD);
|
||||
bool EconomyItemWritable(DWORD);
|
||||
bool EconomyCanDelete(DWORD);
|
||||
bool CubePlayerWritable(DWORD);
|
||||
bool CubeAccountLoadable(DWORD,DWORD);
|
||||
bool CubeItemWritable(DWORD);
|
||||
bool CubePeerMayWriteItem(CPeer*,DWORD);
|
||||
DWORD CubeDrainArm(CPeer*,DWORD,uint64_t,const PortCube::Batch&);
|
||||
bool CubeDrainSubmit(CPeer*,DWORD,uint64_t,DWORD);
|
||||
void CubeMainFence(DWORD,unsigned,bool);
|
||||
void CubeDrainTick();
|
||||
bool CubeMemoryLoadable(DWORD,DWORD);
|
||||
bool CubePeerMaySave(CPeer*,DWORD);
|
||||
void CubePeerGone(DWORD);
|
||||
void CubeAccountLogout(CPeer*,const char*,DWORD);
|
||||
void CubeAccountGone(DWORD,DWORD);
|
||||
void CubeHandshakeRequest(CPeer*,DWORD,const char*,DWORD);
|
||||
void CubeHandshakeRoute(CPeer*,DWORD,const PortCube::Handshake&);
|
||||
void CubeLiveResumeCheckRoute(CPeer*,DWORD,const PortCube::Handshake&);
|
||||
bool CubeRecoveryClaim(CPeer*,DWORD,DWORD,DWORD,uint64_t,PortCube::OwnerGrant&);
|
||||
void CubeRecoveryRoute(CPeer*,DWORD,const PortCube::Handshake&);
|
||||
void CubeRecoveryImageRoute(CPeer*,DWORD,const PortCube::Handshake&);
|
||||
void CubeCraftRoute(CPeer*,DWORD,const PortCube::Handshake&);
|
||||
void CubeLiveImageRoute(CPeer*,DWORD,const PortCube::Handshake&);
|
||||
void CubeLiveImageAckRoute(CPeer*,DWORD,const PortCube::Handshake&);
|
||||
void CubeLiveReleaseRoute(CPeer*,DWORD,const PortCube::Handshake&);
|
||||
typedef std::list<CPeer *> TPeerList;
|
||||
typedef std::unordered_map<DWORD, CPlayerTableCache *> TPlayerTableCacheMap;
|
||||
typedef std::unordered_map<DWORD, CItemCache *> TItemCacheMap;
|
||||
|
||||
@@ -157,7 +157,11 @@ void CClientManager::QUERY_LOGIN_BY_KEY(CPeer * pkPeer, DWORD dwHandle, TPacketG
|
||||
|
||||
sys_log(0, "LOGIN_BY_KEY success %s %lu %s", r.login, p->dwLoginKey, info->ip);
|
||||
char szQuery[QUERY_MAX_LEN];
|
||||
#ifdef ENABLE_PLAYER_PER_ACCOUNT5
|
||||
snprintf(szQuery, sizeof(szQuery), "SELECT pid1, pid2, pid3, pid4, pid5, empire FROM player_index%s WHERE id=%u", GetTablePostfix(), r.id);
|
||||
#else
|
||||
snprintf(szQuery, sizeof(szQuery), "SELECT pid1, pid2, pid3, pid4, empire FROM player_index%s WHERE id=%u", GetTablePostfix(), r.id);
|
||||
#endif
|
||||
CDBManager::instance().ReturnQuery(szQuery, QID_LOGIN_BY_KEY, pkPeer->GetHandle(), info);
|
||||
}
|
||||
|
||||
@@ -179,7 +183,11 @@ void CClientManager::RESULT_LOGIN_BY_KEY(CPeer * peer, SQLMsg * msg)
|
||||
{
|
||||
DWORD account_id = info->pAccountTable->id;
|
||||
char szQuery[QUERY_MAX_LEN];
|
||||
#ifdef ENABLE_PLAYER_PER_ACCOUNT5
|
||||
snprintf(szQuery, sizeof(szQuery), "SELECT pid1, pid2, pid3, pid4, pid5, empire FROM player_index%s WHERE id=%u", GetTablePostfix(), account_id);
|
||||
#else
|
||||
snprintf(szQuery, sizeof(szQuery), "SELECT pid1, pid2, pid3, pid4, empire FROM player_index%s WHERE id=%u", GetTablePostfix(), account_id);
|
||||
#endif
|
||||
std::unique_ptr<SQLMsg> pMsg(CDBManager::instance().DirectQuery(szQuery, SQL_PLAYER));
|
||||
|
||||
sys_log(0, "RESULT_LOGIN_BY_KEY FAIL player_index's NULL : ID:%d", account_id);
|
||||
@@ -211,13 +219,13 @@ void CClientManager::RESULT_LOGIN_BY_KEY(CPeer * peer, SQLMsg * msg)
|
||||
if (g_stLocale == "gb2312")
|
||||
{
|
||||
snprintf(szQuery, sizeof(szQuery),
|
||||
"SELECT id, name, job, level, alignment, st, ht, dx, iq, part_main, part_hair, x, y, skill_group, change_name FROM player%s WHERE account_id=%u",
|
||||
"SELECT id, name, job, level, alignment, st, ht, dx, iq, part_main, part_hair, x, y, skill_group, change_name, conquerorlevel, sungma_str, sungma_hp, sungma_move, sungma_inmune FROM player%s WHERE account_id=%u",
|
||||
GetTablePostfix(), info->pAccountTable->id);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(szQuery, sizeof(szQuery),
|
||||
"SELECT id, name, job, level, playtime, st, ht, dx, iq, part_main, part_hair, x, y, skill_group, change_name FROM player%s WHERE account_id=%u",
|
||||
"SELECT id, name, job, level, playtime, st, ht, dx, iq, part_main, part_hair, x, y, skill_group, change_name, conquerorlevel, sungma_str, sungma_hp, sungma_move, sungma_inmune FROM player%s WHERE account_id=%u",
|
||||
GetTablePostfix(), info->pAccountTable->id);
|
||||
}
|
||||
|
||||
@@ -231,7 +239,11 @@ void CClientManager::RESULT_PLAYER_INDEX_CREATE(CPeer * pkPeer, SQLMsg * msg)
|
||||
ClientHandleInfo * info = (ClientHandleInfo *) qi->pvData;
|
||||
|
||||
char szQuery[QUERY_MAX_LEN];
|
||||
#ifdef ENABLE_PLAYER_PER_ACCOUNT5
|
||||
snprintf(szQuery, sizeof(szQuery), "SELECT pid1, pid2, pid3, pid4, pid5, empire FROM player_index%s WHERE id=%u", GetTablePostfix(),
|
||||
#else
|
||||
snprintf(szQuery, sizeof(szQuery), "SELECT pid1, pid2, pid3, pid4, empire FROM player_index%s WHERE id=%u", GetTablePostfix(),
|
||||
#endif
|
||||
info->pAccountTable->id);
|
||||
CDBManager::instance().ReturnQuery(szQuery, QID_LOGIN_BY_KEY, pkPeer->GetHandle(), info);
|
||||
}
|
||||
@@ -313,6 +325,11 @@ void CreateAccountPlayerDataFromRes(MYSQL_RES * pRes, TAccountTable * pkTab)
|
||||
pkTab->players[j].y = pt->y;
|
||||
pkTab->players[j].skill_group = pt->skill_group;
|
||||
pkTab->players[j].bChangeName = 0;
|
||||
pkTab->players[j].byConquerorLevel = pt->conquerorlevel;
|
||||
pkTab->players[j].bySungmaST = pt->sungma_str;
|
||||
pkTab->players[j].bySungmaHP = pt->sungma_hp;
|
||||
pkTab->players[j].bySungmaMove = pt->sungma_move;
|
||||
pkTab->players[j].bySungmaInmune = pt->sungma_inmune;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -334,6 +351,11 @@ void CreateAccountPlayerDataFromRes(MYSQL_RES * pRes, TAccountTable * pkTab)
|
||||
pkTab->players[j].y = 0;
|
||||
pkTab->players[j].skill_group = 0;
|
||||
pkTab->players[j].bChangeName = 0;
|
||||
pkTab->players[j].byConquerorLevel = 0;
|
||||
pkTab->players[j].bySungmaST = 0;
|
||||
pkTab->players[j].bySungmaHP = 0;
|
||||
pkTab->players[j].bySungmaMove = 0;
|
||||
pkTab->players[j].bySungmaInmune = 0;
|
||||
|
||||
str_to_number(pkTab->players[j].byJob, row[col++]);
|
||||
str_to_number(pkTab->players[j].byLevel, row[col++]);
|
||||
@@ -348,6 +370,11 @@ void CreateAccountPlayerDataFromRes(MYSQL_RES * pRes, TAccountTable * pkTab)
|
||||
str_to_number(pkTab->players[j].y, row[col++]);
|
||||
str_to_number(pkTab->players[j].skill_group, row[col++]);
|
||||
str_to_number(pkTab->players[j].bChangeName, row[col++]);
|
||||
str_to_number(pkTab->players[j].byConquerorLevel, row[col++]);
|
||||
str_to_number(pkTab->players[j].bySungmaST, row[col++]);
|
||||
str_to_number(pkTab->players[j].bySungmaHP, row[col++]);
|
||||
str_to_number(pkTab->players[j].bySungmaMove, row[col++]);
|
||||
str_to_number(pkTab->players[j].bySungmaInmune, row[col++]);
|
||||
}
|
||||
|
||||
sys_log(0, "%s %lu %lu hair %u",
|
||||
@@ -399,13 +426,13 @@ void CClientManager::RESULT_LOGIN(CPeer * peer, SQLMsg * msg)
|
||||
if (g_stLocale == "gb2312")
|
||||
{
|
||||
snprintf(queryStr, sizeof(queryStr),
|
||||
"SELECT id, name, job, level, alignment, st, ht, dx, iq, part_main, part_hair, x, y, skill_group, change_name FROM player%s WHERE account_id=%u",
|
||||
"SELECT id, name, job, level, alignment, st, ht, dx, iq, part_main, part_hair, x, y, skill_group, change_name, conquerorlevel, sungma_str, sungma_hp, sungma_move, sungma_inmune FROM player%s WHERE account_id=%u",
|
||||
GetTablePostfix(), info->pAccountTable->id);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(queryStr, sizeof(queryStr),
|
||||
"SELECT id, name, job, level, playtime, st, ht, dx, iq, part_main, part_hair, x, y, skill_group, change_name FROM player%s WHERE account_id=%u",
|
||||
"SELECT id, name, job, level, playtime, st, ht, dx, iq, part_main, part_hair, x, y, skill_group, change_name, conquerorlevel, sungma_str, sungma_hp, sungma_move, sungma_inmune FROM player%s WHERE account_id=%u",
|
||||
GetTablePostfix(), info->pAccountTable->id);
|
||||
}
|
||||
|
||||
|
||||
@@ -133,6 +133,14 @@ size_t CreatePlayerSaveQuery(char * pszQuery, size_t querySize, TPlayerTable * p
|
||||
"last_play = NOW(), "
|
||||
"skill_group = %d, "
|
||||
"alignment = %ld, "
|
||||
"conquerorlevel = %d, "
|
||||
"conqueror_level_step = %d, "
|
||||
"sungma_str = %d, "
|
||||
"sungma_hp = %d, "
|
||||
"sungma_move = %d, "
|
||||
"sungma_inmune = %d, "
|
||||
"conqueror_exp = %u, "
|
||||
"conqueror_point = %d, "
|
||||
"horse_level = %d, "
|
||||
"horse_riding = %d, "
|
||||
"horse_hp = %d, "
|
||||
@@ -180,6 +188,14 @@ size_t CreatePlayerSaveQuery(char * pszQuery, size_t querySize, TPlayerTable * p
|
||||
pkTab->parts[PART_HAIR],
|
||||
pkTab->skill_group,
|
||||
pkTab->lAlignment,
|
||||
pkTab->conquerorlevel,
|
||||
pkTab->conqueror_level_step,
|
||||
pkTab->sungma_str,
|
||||
pkTab->sungma_hp,
|
||||
pkTab->sungma_move,
|
||||
pkTab->sungma_inmune,
|
||||
pkTab->conqueror_exp,
|
||||
pkTab->conqueror_point,
|
||||
pkTab->horse.bLevel,
|
||||
pkTab->horse.bRiding,
|
||||
pkTab->horse.sHealth,
|
||||
@@ -415,7 +431,7 @@ void CClientManager::QUERY_PLAYER_LOAD(CPeer * peer, DWORD dwHandle, TPlayerLoad
|
||||
"id,name,job,voice,dir,x,y,z,map_index,exit_x,exit_y,exit_map_index,hp,mp,stamina,random_hp,random_sp,playtime,"
|
||||
"gold,level,level_step,st,ht,dx,iq,exp,"
|
||||
"stat_point,skill_point,sub_skill_point,stat_reset_count,part_base,part_hair,"
|
||||
"skill_level,quickslot,skill_group,alignment,mobile,horse_level,horse_riding,horse_hp,horse_hp_droptime,horse_stamina,"
|
||||
"skill_level,quickslot,skill_group,alignment,conquerorlevel,conqueror_level_step,sungma_str,sungma_hp,sungma_move,sungma_inmune,conqueror_exp,conqueror_point,mobile,horse_level,horse_riding,horse_hp,horse_hp_droptime,horse_stamina,"
|
||||
"UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(last_play),horse_skill_point"
|
||||
#ifdef UNLOCK_INVENTORY_WORLDARD
|
||||
",inventory_0,inventory_1,inventory_2,inventory_3,inventory_4,inventory_5"
|
||||
@@ -570,6 +586,14 @@ bool CreatePlayerTableFromRes(MYSQL_RES * res, TPlayerTable * pkTab)
|
||||
|
||||
str_to_number(pkTab->skill_group, row[col++]);
|
||||
str_to_number(pkTab->lAlignment, row[col++]);
|
||||
str_to_number(pkTab->conquerorlevel, row[col++]);
|
||||
str_to_number(pkTab->conqueror_level_step, row[col++]);
|
||||
str_to_number(pkTab->sungma_str, row[col++]);
|
||||
str_to_number(pkTab->sungma_hp, row[col++]);
|
||||
str_to_number(pkTab->sungma_move, row[col++]);
|
||||
str_to_number(pkTab->sungma_inmune, row[col++]);
|
||||
str_to_number(pkTab->conqueror_exp, row[col++]);
|
||||
str_to_number(pkTab->conqueror_point, row[col++]);
|
||||
|
||||
if (row[col])
|
||||
{
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
#include "stdafx.h"
|
||||
#include "ClientManager.h"
|
||||
#include "Cache.h"
|
||||
#include "Main.h"
|
||||
#include <memory>
|
||||
|
||||
namespace {
|
||||
using CubeQuery=std::unique_ptr<SQLMsg>;
|
||||
CubeQuery cubeQuery(const std::string& sql){return CubeQuery(CDBManager::instance().DirectQuery(sql.c_str()));}
|
||||
bool cubeValid(const CubeQuery& q){return q&&!q->uiSQLErrno&&q->Get();}
|
||||
// No table installation at runtime. Cache only a completely absent schema;
|
||||
// migrations require coordinated restart. Partial/failed discovery fails closed.
|
||||
int cubeSchema() {
|
||||
static int state=-1;if(state>=0)return state;
|
||||
auto q=cubeQuery("SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN ('port_cube_version','port_cube_fences','port_cube_item_fences')");
|
||||
if(!cubeValid(q)||q->Get()->uiNumRows!=1)return -1;
|
||||
MYSQL_ROW row=mysql_fetch_row(q->Get()->pSQLResult);if(!row||!row[0])return -1;
|
||||
const std::string count=row[0];
|
||||
if(count=="0")return state=0;
|
||||
if(count=="3") {
|
||||
auto version=cubeQuery("SELECT version FROM port_cube_version WHERE id=1");
|
||||
if(!cubeValid(version)||version->Get()->uiNumRows!=1)return -1;
|
||||
MYSQL_ROW value=mysql_fetch_row(version->Get()->pSQLResult);
|
||||
if(value&&value[0]&&std::string(value[0])=="2")return state=1;
|
||||
}
|
||||
return -1; // includes the older two-table v1 candidate: do not ignore fences
|
||||
}
|
||||
bool cubeClear(const std::string& predicate) {
|
||||
const int installed=cubeSchema();if(installed==0)return true;if(installed<0)return false;
|
||||
auto q=cubeQuery("SELECT pid FROM port_cube_fences WHERE phase<>'RELEASED' AND ("+predicate+") LIMIT 1");
|
||||
return cubeValid(q)&&q->Get()->uiNumRows==0;
|
||||
}
|
||||
// Modern terminal release is not a completed resume. Keep the SQL quarantine
|
||||
// across DB restart, when m_cubeDrains no longer carries its memory hold.
|
||||
// No resume activation receipt exists yet; do not infer one from RELEASED.
|
||||
int cubeTerminalSchema() {
|
||||
static int installed=-1;if(installed>=0)return installed;
|
||||
const std::string names="('port_cube_release_version','port_cube_releases')";
|
||||
auto scalar=[](const std::string& sql,const std::string& expected)->bool{auto q=cubeQuery(sql);if(!cubeValid(q)||q->Get()->uiNumRows!=1)return false;MYSQL_ROW row=mysql_fetch_row(q->Get()->pSQLResult);return row&&row[0]&&std::string(row[0])==expected;};
|
||||
auto q=cubeQuery("SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN "+names);
|
||||
if(!cubeValid(q)||q->Get()->uiNumRows!=1)return -1;MYSQL_ROW row=mysql_fetch_row(q->Get()->pSQLResult);if(!row||!row[0])return -1;
|
||||
const std::string count=row[0];if(count=="0")return installed=0;
|
||||
if(count!="2"||!scalar("SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA=DATABASE() AND ENGINE='InnoDB' AND TABLE_NAME IN "+names,"2")||!scalar("SELECT version FROM port_cube_release_version WHERE id=1","1"))return -1;
|
||||
return installed=1;
|
||||
}
|
||||
bool cubeTerminalClear(const std::string& predicate) {
|
||||
const int schema=cubeTerminalSchema();if(schema==0)return true;if(schema<0)return false;
|
||||
auto q=cubeQuery("SELECT pid FROM port_cube_fences WHERE phase='RELEASED' AND request IN (SELECT request FROM port_cube_releases) AND ("+predicate+") LIMIT 1");
|
||||
return cubeValid(q)&&q->Get()->uiNumRows==0;
|
||||
}
|
||||
bool cubeGoldClear(const std::string& predicate) {
|
||||
// Coordinated restart on installation/removal, as with the base Cube gate.
|
||||
static int installed=-1;
|
||||
if(installed<0) {
|
||||
auto q=cubeQuery("SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN ('port_cube_gold_version','port_cube_gold_intents','port_cube_gold_sources')");
|
||||
if(!cubeValid(q)||q->Get()->uiNumRows!=1)return false;
|
||||
MYSQL_ROW row=mysql_fetch_row(q->Get()->pSQLResult);if(!row||!row[0])return false;
|
||||
if(std::string(row[0])=="0")installed=0;
|
||||
else if(std::string(row[0])=="3") {
|
||||
auto engine=cubeQuery("SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA=DATABASE() AND ENGINE='InnoDB' AND TABLE_NAME IN ('port_cube_gold_version','port_cube_gold_intents','port_cube_gold_sources')");
|
||||
if(!cubeValid(engine)||engine->Get()->uiNumRows!=1)return false;
|
||||
MYSQL_ROW e=mysql_fetch_row(engine->Get()->pSQLResult);if(!e||!e[0]||std::string(e[0])!="3")return false;
|
||||
auto version=cubeQuery("SELECT version FROM port_cube_gold_version WHERE id=1");
|
||||
if(!cubeValid(version)||version->Get()->uiNumRows!=1)return false;
|
||||
MYSQL_ROW v=mysql_fetch_row(version->Get()->pSQLResult);if(!v||!v[0]||std::string(v[0])!="2")return false;
|
||||
installed=1;
|
||||
} else return false;
|
||||
}
|
||||
if(!installed)return true;
|
||||
auto q=cubeQuery("SELECT pid FROM port_cube_gold_intents WHERE state='QUEUED' AND ("+predicate+") LIMIT 1");
|
||||
return cubeValid(q)&&q->Get()->uiNumRows==0;
|
||||
}
|
||||
bool cubeOwnerClear(const std::string& predicate) {
|
||||
static int installed=-1;
|
||||
const std::string names="('port_cube_owner_version','port_cube_owner_broker','port_cube_owner_leases')";
|
||||
auto scalar=[](const std::string& sql,const std::string& expected)->bool {
|
||||
auto q=cubeQuery(sql);if(!cubeValid(q)||q->Get()->uiNumRows!=1)return false;
|
||||
MYSQL_ROW row=mysql_fetch_row(q->Get()->pSQLResult);return row&&row[0]&&std::string(row[0])==expected;
|
||||
};
|
||||
if(installed<0) {
|
||||
auto q=cubeQuery("SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN "+names);
|
||||
if(!cubeValid(q)||q->Get()->uiNumRows!=1)return false;
|
||||
MYSQL_ROW row=mysql_fetch_row(q->Get()->pSQLResult);if(!row||!row[0])return false;
|
||||
if(std::string(row[0])=="0")installed=0;
|
||||
else if(std::string(row[0])=="3"&&scalar("SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA=DATABASE() AND ENGINE='InnoDB' AND TABLE_NAME IN "+names,"3")&&
|
||||
scalar("SELECT version FROM port_cube_owner_version WHERE id=1","1"))installed=1;
|
||||
else return false;
|
||||
}
|
||||
if(!installed)return true;
|
||||
// Includes REVOKED and ADOPTED. Neither is a normal-load/thaw receipt.
|
||||
auto q=cubeQuery("SELECT pid FROM port_cube_owner_leases WHERE "+predicate+" LIMIT 1");
|
||||
return cubeValid(q)&&q->Get()->uiNumRows==0;
|
||||
}
|
||||
}
|
||||
|
||||
bool CClientManager::CubePeerMayWriteItem(CPeer* peer,DWORD id) {
|
||||
if(*GetTablePostfix())return true;
|
||||
if(!id)return false;
|
||||
bool protectedActor=false;
|
||||
auto allowed=[&](DWORD pid)->bool {
|
||||
for(const auto& entry:m_cubeDrains)if(!entry.second.cancelled&&entry.second.batch.player==pid)
|
||||
return CubePeerMaySave(peer,pid);
|
||||
return true;
|
||||
};
|
||||
for(const auto& entry:m_cubeDrains) {
|
||||
const auto& c=entry.second;if(c.cancelled)continue;protectedActor=true;
|
||||
// Includes consumed inputs and not-yet-created reserved rewards. Never
|
||||
// trust a packet's claimed owner or lack of a current SQL item row.
|
||||
for(const auto& item:c.batch.inventory)if(item.value.id==id&&!allowed(c.batch.player))return false;
|
||||
for(const auto& reward:c.batch.rewards)if(reward.id==id&&!allowed(c.batch.player))return false;
|
||||
}
|
||||
if(!protectedActor)return true; // no extra SQL or cache access on baseline
|
||||
if(auto* cache=GetItemCache(id)) {
|
||||
const auto* item=cache->Get(false);
|
||||
if(!item||item->id!=id)return false;
|
||||
if(item->window!=SAFEBOX&&item->window!=MALL&&!allowed(item->owner))return false;
|
||||
}
|
||||
// Check BOTH cached and persisted ownership. A stale cache or a forged
|
||||
// SAFEBOX/MALL destination cannot conceal a protected ordinary SQL owner.
|
||||
auto owner=cubeQuery("SELECT owner_id FROM item WHERE id="+std::to_string(id)+" AND window NOT IN ('MALL','SAFEBOX')");
|
||||
if(!cubeValid(owner)||owner->Get()->uiNumRows>1)return false;
|
||||
if(owner->Get()->uiNumRows){MYSQL_ROW row=mysql_fetch_row(owner->Get()->pSQLResult);uint64_t pid=0;if(!row||!row[0]||!PortEconomy::Number(row[0],pid,UINT32_MAX)||!pid||!allowed(DWORD(pid)))return false;}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CClientManager::CubePlayerWritable(DWORD pid) {
|
||||
if(*GetTablePostfix())return true;
|
||||
if(!cubeTerminalClear("pid="+std::to_string(pid)))return false;
|
||||
if(!pid||!cubeOwnerClear("pid="+std::to_string(pid)))return false;
|
||||
if(!pid||!cubeGoldClear("pid="+std::to_string(pid)))return false;
|
||||
if(!pid||!cubeClear("pid="+std::to_string(pid)))return false;
|
||||
if(cubeSchema()==0)return true;
|
||||
auto q=cubeQuery("SELECT pid FROM port_cube_item_fences WHERE pid="+std::to_string(pid)+" LIMIT 1");
|
||||
return cubeValid(q)&&q->Get()->uiNumRows==0;
|
||||
}
|
||||
bool CClientManager::CubeAccountLoadable(DWORD account,DWORD pid) {
|
||||
if(*GetTablePostfix())return true;
|
||||
if(!cubeTerminalClear("account="+std::to_string(account)+" OR pid="+std::to_string(pid)))return false;
|
||||
if(!account||!pid||!cubeOwnerClear("account="+std::to_string(account)+" OR pid="+std::to_string(pid)))return false;
|
||||
if(!account||!pid||!cubeGoldClear("account="+std::to_string(account)+" OR pid="+std::to_string(pid)))return false;
|
||||
// Also stop selecting another character on an account with a held owner.
|
||||
if(!account||!pid||!cubeClear("account="+std::to_string(account)+" OR pid="+std::to_string(pid)))return false;
|
||||
if(cubeSchema()==0)return true;
|
||||
auto q=cubeQuery("SELECT f.pid FROM port_cube_item_fences f LEFT JOIN player p ON p.id=f.pid WHERE f.pid="+std::to_string(pid)+" OR p.account_id="+std::to_string(account)+" LIMIT 1");
|
||||
return cubeValid(q)&&q->Get()->uiNumRows==0;
|
||||
}
|
||||
bool CClientManager::CubeItemWritable(DWORD id) {
|
||||
if(*GetTablePostfix())return true;
|
||||
const int installed=cubeSchema();if(installed==0)return true;if(installed<0||!id)return false;
|
||||
const int terminal=cubeTerminalSchema();if(terminal<0)return false;
|
||||
if(terminal) {
|
||||
auto reservation=cubeQuery("SELECT f.pid FROM port_cube_fences f JOIN port_cube_releases r ON r.request=f.request JOIN port_economy_item_reservations i ON i.request=f.request WHERE f.phase='RELEASED' AND i.id="+std::to_string(id)+" LIMIT 1");
|
||||
if(!cubeValid(reservation)||reservation->Get()->uiNumRows)return false;
|
||||
auto owner=cubeQuery("SELECT owner_id FROM item WHERE id="+std::to_string(id)+" AND window NOT IN ('MALL','SAFEBOX')");
|
||||
if(!cubeValid(owner)||owner->Get()->uiNumRows>1)return false;
|
||||
if(owner->Get()->uiNumRows){MYSQL_ROW row=mysql_fetch_row(owner->Get()->pSQLResult);uint64_t pid=0;if(!row||!row[0]||!PortEconomy::Number(row[0],pid,UINT32_MAX)||!pid||!cubeTerminalClear("pid="+std::to_string(pid)))return false;}
|
||||
}
|
||||
// SQL RELEASED is not the save/resume handoff. ID-only legacy destroy and
|
||||
// flush packets cannot bypass a still-held playing context after SQL locks
|
||||
// retire. Batch IDs include consumed inputs and unissued reserved rewards.
|
||||
bool held=false;
|
||||
for(const auto& entry:m_cubeDrains) {
|
||||
const auto& c=entry.second;if(!c.began||c.cancelled)continue;held=true;
|
||||
for(const auto& item:c.batch.inventory)if(item.value.id==id)return false;
|
||||
for(const auto& reward:c.batch.rewards)if(reward.id==id)return false;
|
||||
}
|
||||
if(held) {
|
||||
auto owner=cubeQuery("SELECT owner_id FROM item WHERE id="+std::to_string(id)+" AND window NOT IN ('MALL','SAFEBOX')");
|
||||
if(!cubeValid(owner)||owner->Get()->uiNumRows>1)return false;
|
||||
if(owner->Get()->uiNumRows) {
|
||||
MYSQL_ROW row=mysql_fetch_row(owner->Get()->pSQLResult);uint64_t pid=0;
|
||||
if(!row||!row[0]||!PortEconomy::Number(row[0],pid,UINT32_MAX)||!pid)return false;
|
||||
for(const auto& entry:m_cubeDrains)if(entry.second.began&&!entry.second.cancelled&&entry.second.batch.player==pid)return false;
|
||||
}
|
||||
}
|
||||
// No JOIN against item: consumed input IDs no longer have an item row, and
|
||||
// owner-less legacy destroy packets must still be denied until resync ACK.
|
||||
auto q=cubeQuery("SELECT id FROM port_cube_item_fences WHERE id="+std::to_string(id)+" LIMIT 1");
|
||||
return cubeValid(q)&&q->Get()->uiNumRows==0;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
#include "../../common/economy_mysql.h"
|
||||
#include "../../common/cube_gold_store.h"
|
||||
// Compile the complete candidate against the real pinned MySQL adapter. No
|
||||
// runtime caller or producer registration is installed by this instantiation.
|
||||
template class PortCube::GoldIntentStore<PortEconomy::Mysql>;
|
||||
@@ -0,0 +1,536 @@
|
||||
#include "stdafx.h"
|
||||
#include "ClientManager.h"
|
||||
#include "Cache.h"
|
||||
#include "Main.h"
|
||||
#include "../../common/cube_fence.h"
|
||||
#include "../../common/cube_gold_store.h"
|
||||
#include "../../common/cube_owner.h"
|
||||
#include "../../common/cube_image_ack.h"
|
||||
#include "../../common/cube_release.h"
|
||||
#include "../../common/cube_random.h"
|
||||
#include "../../common/economy_mysql.h"
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
bool CClientManager::CubeDrainOwner(const PortCube::RuntimeDrain& context,bool lifecycleOnly) {
|
||||
auto* peer=GetPeer(context.peer);
|
||||
auto* login=GetLoginDataByAID(context.batch.account);
|
||||
if((context.ownerLost&&!lifecycleOnly)||!peer||!peer->GetChannel()||!login||login->IsPlay()==context.recovery||login->GetConnectedPeerHandle()!=context.peer)return false;
|
||||
for(const auto& player:login->GetAccountRef().players)if(player.dwID==context.batch.player)return true;
|
||||
return false;
|
||||
}
|
||||
bool CClientManager::CubeAuthorityCheck(const PortCube::RuntimeDrain& c,bool lease) {
|
||||
auto& db=CDBManager::instance();PortEconomy::Mysql mysql(db.DirectHandle());
|
||||
PortCube::OwnerStore<PortEconomy::Mysql> owner(mysql,[&](uint32_t v){auto it=m_map_itemTableByVnum.find(v);return it==m_map_itemTableByVnum.end()?PortCube::Proto{}:PortCube::Proto{unsigned(it->second->bSize),bool(it->second->dwFlags&ITEM_FLAG_STACKABLE)};});
|
||||
return lease?owner.Check(c.batch,c.ownership):owner.Current(c.ownership.leader);
|
||||
}
|
||||
void CClientManager::CubeAuthorityRevoke(PortCube::RuntimeDrain& c,unsigned reason) {
|
||||
if(!c.began||c.revocationDone)return;auto& db=CDBManager::instance();PortEconomy::Mysql mysql(db.DirectHandle());
|
||||
auto lookup=[&](uint32_t v){auto it=m_map_itemTableByVnum.find(v);return it==m_map_itemTableByVnum.end()?PortCube::Proto{}:PortCube::Proto{unsigned(it->second->bSize),bool(it->second->dwFlags&ITEM_FLAG_STACKABLE)};};
|
||||
PortCube::OwnerStore<PortEconomy::Mysql> owner(mysql,lookup);
|
||||
PortCube::OwnerGrant receipt;const auto result=owner.Revoke(c.batch,c.ownership.leader,reason,&c.ownership,receipt);
|
||||
c.revocationDone=result==PortCube::OwnerStore<PortEconomy::Mysql>::Revoked;
|
||||
if(!c.revocationDone&&!c.recovery&&result==PortCube::OwnerStore<PortEconomy::Mysql>::Refused) {
|
||||
// Release COMMIT can precede peer loss and its reply. Only exact durable
|
||||
// terminal proof retires revocation work; token/empty lease is not proof.
|
||||
PortCube::Batch saved;std::string phase,image;PortCube::FenceStore<PortEconomy::Mysql> fence(mysql,lookup);
|
||||
PortCube::ReleaseStore<PortEconomy::Mysql> release(mysql,lookup);
|
||||
if(fence.Recover(c.batch.account,c.batch.player,saved,phase,image)==PortCube::FenceStore<PortEconomy::Mysql>::Done&&
|
||||
phase=="RELEASED"&&PortCube::Encode(saved)==PortCube::Encode(c.batch)&&release.ReleaseLive(c.batch,c.ownership,image)==PortCube::ReleaseStore<PortEconomy::Mysql>::Released) {
|
||||
c.phase="RELEASED";c.revocationDone=true; // memory save/load hold remains
|
||||
}
|
||||
}
|
||||
if(!c.revocationDone&&c.recovery&&result==PortCube::OwnerStore<PortEconomy::Mysql>::Refused) {
|
||||
// A Retry may have occurred before adoption committed. Retire only
|
||||
// after reading durable proof that this proposed grant is NOT current.
|
||||
std::string phase;uint64_t revoked=0;
|
||||
if(owner.Inspect(c.batch,c.ownership.leader,receipt,phase,revoked)&&!PortCube::SameOwnerGrant(receipt,c.ownership)&&
|
||||
(receipt.revision>=c.ownership.revision||(phase=="REVOKED"&&receipt.revision!=UINT64_MAX&&receipt.revision+1==c.ownership.revision)))c.revocationDone=true;
|
||||
}
|
||||
if(!c.revocationDone)c.nextRevocation=time(nullptr)+5;
|
||||
}
|
||||
|
||||
// Recovery preparation only. The gated internal game/DB route may call this;
|
||||
// no normal player load, currency write, image ACK or thaw is authorized here.
|
||||
bool CClientManager::CubeRecoveryClaim(CPeer* peer,DWORD handle,DWORD account,DWORD pid,uint64_t session,PortCube::OwnerGrant& grant) {
|
||||
using namespace PortCube;grant={};
|
||||
if(*GetTablePostfix()||!peer||!peer->GetChannel()||!handle||!account||!pid||!session)return false;
|
||||
auto* login=GetLoginDataByAID(account);
|
||||
if(!login||login->IsPlay()||login->GetConnectedPeerHandle()!=peer->GetHandle()||GetPeer(peer->GetHandle())!=peer)return false;
|
||||
bool member=false;for(const auto& player:login->GetAccountRef().players)if(player.dwID==pid)member=true;
|
||||
if(!member)return false;
|
||||
auto lookup=[&](uint32_t v){auto it=m_map_itemTableByVnum.find(v);return it==m_map_itemTableByVnum.end()?Proto{}:Proto{unsigned(it->second->bSize),bool(it->second->dwFlags&ITEM_FLAG_STACKABLE)};};
|
||||
auto& db=CDBManager::instance();PortEconomy::Mysql mysql(db.DirectHandle());OwnerStore<PortEconomy::Mysql> owner(mysql,lookup);
|
||||
if(m_cubeOwnerBoot.empty())m_cubeOwnerBoot=OwnerBootNonce();
|
||||
OwnerLeader leader;if(owner.Acquire(m_cubeOwnerBoot,leader)!=OwnerStore<PortEconomy::Mysql>::Acquired)return false;
|
||||
Batch batch;std::string phase,image;FenceStore<PortEconomy::Mysql> fence(mysql,lookup);
|
||||
if(fence.Recover(account,pid,batch,phase,image)!=FenceStore<PortEconomy::Mysql>::Done)return false;
|
||||
OwnerGrant active;uint64_t revoked=0;
|
||||
if(!owner.Inspect(batch,leader,active,phase,revoked))return false;
|
||||
auto remember=[&](const OwnerGrant& held)->bool {
|
||||
auto found=m_cubeDrains.find(held.binding.cookie);
|
||||
if(found!=m_cubeDrains.end())return found->second.recovery&&!found->second.ownerLost&&!found->second.revocationReason&&PortCube::SameOwnerGrant(found->second.ownership,held)&&PortCube::Encode(found->second.batch)==PortCube::Encode(batch);
|
||||
if(m_cubeDrains.size()>=128)return false;
|
||||
RuntimeDrain c;c.batch=batch;c.ownership=held;c.peer=held.peer;c.handle=held.binding.handle;c.session=held.binding.session;
|
||||
c.began=c.queued=c.finished=c.recovery=true;c.phase="ADOPTED";c.created=time(nullptr);
|
||||
m_cubeDrains.emplace(held.binding.cookie,std::move(c));m_cubeCookie=std::max(m_cubeCookie,held.binding.cookie);return true;
|
||||
};
|
||||
// Lost adoption ACK: return the exact persisted grant, never a fresh cookie.
|
||||
if(phase=="ADOPTED"&&active.leader.boot==leader.boot&&active.leader.generation==leader.generation&&active.leader.connection==leader.connection&&
|
||||
active.peer==peer->GetHandle()&&active.binding.handle==handle&&active.binding.session==session){if(!remember(active))return false;grant=active;return true;}
|
||||
if(active.leader.generation<leader.generation) {
|
||||
OwnerGrant receipt;if(owner.Revoke(batch,leader,3,nullptr,receipt)!=OwnerStore<PortEconomy::Mysql>::Revoked)return false;
|
||||
active=receipt;phase="REVOKED";revoked=leader.generation;
|
||||
}
|
||||
if(phase!="REVOKED"||revoked!=leader.generation||active.revision==UINT64_MAX||session==active.binding.session)return false;
|
||||
OwnerGrant proposal;
|
||||
for(const auto& entry:m_cubeDrains) {
|
||||
const auto& c=entry.second;
|
||||
if(c.recovery&&c.batch.token==batch.token&&c.peer==peer->GetHandle()&&c.handle==handle&&c.session==session&&c.ownership.revision==active.revision+1&&
|
||||
c.ownership.leader.boot==leader.boot&&c.ownership.leader.generation==leader.generation&&c.ownership.leader.connection==leader.connection) {
|
||||
if(c.ownerLost||c.revocationReason)return false;proposal=c.ownership;break;
|
||||
}
|
||||
}
|
||||
if(!Valid(proposal)) {
|
||||
if(m_cubeDrains.size()>=128||m_cubeCookie==UINT32_MAX)return false;
|
||||
proposal={leader,GoldSourceFor(batch,session,++m_cubeCookie,handle),peer->GetHandle(),active.revision+1};
|
||||
}
|
||||
const auto result=owner.Adopt(batch,leader,active.revision,peer->GetHandle(),proposal.binding,grant);
|
||||
if(result==OwnerStore<PortEconomy::Mysql>::Refused)return false;
|
||||
// Also retain a Retry proposal: COMMIT may have succeeded before its ACK
|
||||
// was lost. A peer close must be able to revoke it before a client retry.
|
||||
if(!remember(proposal)){grant={};return false;}
|
||||
return result==OwnerStore<PortEconomy::Mysql>::Adopted;
|
||||
}
|
||||
|
||||
DWORD CClientManager::CubeDrainArm(CPeer* peer,DWORD handle,uint64_t session,const PortCube::Batch& batch) {
|
||||
if(*GetTablePostfix()||!peer||!handle||!session||!PortCube::Validate(batch)||m_cubeDrains.size()>=128||m_cubeCookie==UINT32_MAX)return 0;
|
||||
PortCube::RuntimeDrain context;context.batch=batch;context.peer=peer->GetHandle();context.handle=handle;context.session=session;
|
||||
if(!CubeDrainOwner(context)||!CubeMemoryLoadable(batch.account,batch.player)||!CubePlayerWritable(batch.player)||m_economyFences.count(batch.player)||m_economyClosed.count(batch.player))return 0;
|
||||
auto& db=CDBManager::instance();
|
||||
PortEconomy::Mysql mysql(db.DirectHandle());
|
||||
// A modern live owner may produce deferred gold. Do not Arm a source whose
|
||||
// durable enqueue/closure schema is missing, even if the base store exists.
|
||||
PortCube::OwnerStore<PortEconomy::Mysql> store(mysql,[&](uint32_t v){auto it=m_map_itemTableByVnum.find(v);return it==m_map_itemTableByVnum.end()?PortCube::Proto{}:PortCube::Proto{unsigned(it->second->bSize),bool(it->second->dwFlags&ITEM_FLAG_STACKABLE)};});
|
||||
if(!store.Ready())return 0;
|
||||
if(m_cubeOwnerBoot.empty())m_cubeOwnerBoot=PortCube::OwnerBootNonce();
|
||||
PortCube::OwnerLeader leader;if(store.Acquire(m_cubeOwnerBoot,leader)!=PortCube::OwnerStore<PortEconomy::Mysql>::Acquired)return 0;
|
||||
// Capture BEFORE the final-save handoff, not after eviction or first barrier.
|
||||
context.main=db.EconomyFailures(false);context.async=db.EconomyFailures(true);context.router=db.SQLFenceFailures();context.created=time(nullptr);
|
||||
const DWORD cookie=++m_cubeCookie;context.ownership={leader,PortCube::GoldSourceFor(batch,session,cookie,handle),peer->GetHandle(),1};
|
||||
m_cubeDrains.emplace(cookie,std::move(context));return cookie;
|
||||
}
|
||||
|
||||
bool CClientManager::CubeMemoryLoadable(DWORD account,DWORD pid) {
|
||||
for(const auto& entry:m_cubeDrains)if(!entry.second.cancelled&&(entry.second.batch.account==account||entry.second.batch.player==pid))return false;
|
||||
return true;
|
||||
}
|
||||
bool CClientManager::CubePeerMaySave(CPeer* peer,DWORD pid) {
|
||||
for(const auto& entry:m_cubeDrains)if(!entry.second.cancelled&&entry.second.batch.player==pid)
|
||||
return !entry.second.began&&peer&&GetPeer(peer->GetHandle())==peer&&peer->GetHandle()==entry.second.peer&&CubeDrainOwner(entry.second);
|
||||
return true;
|
||||
}
|
||||
void CClientManager::CubePeerGone(DWORD peer) {
|
||||
for(auto& entry:m_cubeDrains)if(entry.second.peer==peer){entry.second.ownerLost=true;entry.second.revocationReason=1;}
|
||||
}
|
||||
void CClientManager::CubeAccountGone(DWORD account,DWORD peer) {
|
||||
if(!account||!peer)return;
|
||||
for(auto& entry:m_cubeDrains)if(entry.second.peer==peer&&entry.second.batch.account==account){entry.second.ownerLost=true;entry.second.revocationReason=2;}
|
||||
}
|
||||
void CClientManager::CubeAccountLogout(CPeer* peer,const char* data,DWORD length) {
|
||||
if(!peer||!data||length!=sizeof(TLogoutPacket))return;
|
||||
TLogoutPacket packet;std::memcpy(&packet,data,sizeof(packet));
|
||||
if(!packet.login[0]||!std::memchr(packet.login,0,sizeof(packet.login)))return;
|
||||
auto* login=GetLoginDataByLogin(packet.login);
|
||||
if(!login||login->GetConnectedPeerHandle()!=peer->GetHandle())return;
|
||||
CubeAccountGone(login->GetAccountRef().id,peer->GetHandle());
|
||||
}
|
||||
|
||||
bool CClientManager::CubeDrainSubmit(CPeer* peer,DWORD handle,uint64_t session,DWORD cookie) {
|
||||
auto it=m_cubeDrains.find(cookie);if(it==m_cubeDrains.end())return false;auto& c=it->second;
|
||||
if(!peer||peer->GetHandle()!=c.peer||handle!=c.handle||session!=c.session||!CubeDrainOwner(c)||c.finished||c.cancelled)return false;
|
||||
if(!CubeAuthorityCheck(c,c.queued))return false;
|
||||
if(c.queued)return true;
|
||||
auto* player=GetPlayerCache(c.batch.player);auto* items=GetItemCacheSet(c.batch.player);
|
||||
if(!player||!items||player->Get(false)->gold!=c.batch.gold)return false;
|
||||
std::vector<uint32_t> ids;std::vector<PortCube::Item> snapshot;
|
||||
for(auto* cache:*items) {
|
||||
const auto* item=cache->Get(false);
|
||||
if(!item->id||item->owner!=c.batch.player||ids.size()>=4096)return false;
|
||||
ids.push_back(item->id); // include gear and dirty tombstones before eviction
|
||||
if(!item->vnum||item->window!=INVENTORY||item->pos>=225)continue;
|
||||
PortCube::Item image;image.usable=false;image.cell=item->pos;image.value.id=item->id;image.value.vnum=item->vnum;image.value.count=item->count;
|
||||
for(unsigned j=0;j<3;++j){if(item->alSockets[j]<INT32_MIN||item->alSockets[j]>INT32_MAX)return false;image.value.sockets[j]=int32_t(item->alSockets[j]);}
|
||||
for(unsigned j=0;j<7;++j){image.value.types[j]=item->aAttr[j].bType;image.value.values[j]=item->aAttr[j].sValue;}
|
||||
static_assert(sizeof(item->extra)==69,"Cube requires the exact extra-item image");
|
||||
std::memcpy(image.value.extra,&item->extra,69);snapshot.push_back(image);
|
||||
}
|
||||
std::sort(ids.begin(),ids.end());if(std::adjacent_find(ids.begin(),ids.end())!=ids.end())return false;
|
||||
std::sort(snapshot.begin(),snapshot.end(),[](const PortCube::Item& a,const PortCube::Item& b){return a.cell<b.cell;});
|
||||
auto expected=c.batch.inventory;
|
||||
// usable describes runtime event/lock ownership, not a SQL column. Game must
|
||||
// validate it while frozen; equality here validates only the persisted image.
|
||||
for(auto& image:expected)image.usable=false;
|
||||
PortCube::Writer actual,wanted;actual.items(snapshot);wanted.items(expected);
|
||||
if(actual.data!=wanted.data)return false;
|
||||
auto& db=CDBManager::instance();PortEconomy::Mysql mysql(db.DirectHandle());
|
||||
PortCube::FenceStore<PortEconomy::Mysql> store(mysql,[&](uint32_t v){auto p=m_map_itemTableByVnum.find(v);return p==m_map_itemTableByVnum.end()?PortCube::Proto{}:PortCube::Proto{unsigned(p->second->bSize),bool(p->second->dwFlags&ITEM_FLAG_STACKABLE)};});
|
||||
// A lost commit ACK may already have installed the fence. Never expire or
|
||||
// accept ordinary saves again after entering Begin, including Retry/Refused.
|
||||
c.began=true;
|
||||
PortCube::OwnerStore<PortEconomy::Mysql> owner(mysql,[&](uint32_t v){auto p=m_map_itemTableByVnum.find(v);return p==m_map_itemTableByVnum.end()?PortCube::Proto{}:PortCube::Proto{unsigned(p->second->bSize),bool(p->second->dwFlags&ITEM_FLAG_STACKABLE)};});
|
||||
if(store.Begin(c.batch,ids,[&](bool replay){return owner.BindWithin(c.batch,c.ownership,replay);})!=PortCube::FenceStore<PortEconomy::Mysql>::Done)return false;
|
||||
PortCube::Batch recovered;std::string phase,image;
|
||||
if(store.Recover(c.batch.account,c.batch.player,recovered,phase,image)!=PortCube::FenceStore<PortEconomy::Mysql>::Done||PortCube::Encode(recovered)!=PortCube::Encode(c.batch)||phase!="DRAINING")return false;
|
||||
if(!c.proof.Start(c.batch,c.session,c.main,c.async))return false;
|
||||
// Flush directly, not via peer QUERY_ITEM_FLUSH, whose ingress is now gated.
|
||||
FlushItemCacheSet(c.batch.player);FlushPlayerCacheSet(c.batch.player);DeleteLogoutPlayer(c.batch.player);
|
||||
c.queued=true;c.phase="DRAINING";
|
||||
db.ReturnQuery("SELECT 1",PortCube::MainFirst,cookie,nullptr);return true;
|
||||
}
|
||||
|
||||
void CClientManager::CubeMainFence(DWORD cookie,unsigned pass,bool failed) {
|
||||
auto it=m_cubeDrains.find(cookie);if(it==m_cubeDrains.end()||!it->second.queued||it->second.finished)return;auto& c=it->second;
|
||||
if(c.proof.Main(c.batch,c.session,pass,failed)==1) {
|
||||
c.phase="FIRST";
|
||||
auto& db=CDBManager::instance();db.ReturnQuery("SELECT 1",PortCube::MainSecond,cookie,nullptr);
|
||||
c.asyncQueued=db.CubeAsyncFence(cookie);
|
||||
}
|
||||
}
|
||||
|
||||
void CClientManager::CubeDrainTick() {
|
||||
auto& db=CDBManager::instance();
|
||||
while(SQLMsg* raw=db.PopCubeAsyncFence()) {
|
||||
std::unique_ptr<SQLMsg> msg(raw);const auto cookie=uint32_t(reinterpret_cast<uintptr_t>(msg->pvUserData));
|
||||
auto it=m_cubeDrains.find(cookie);if(it!=m_cubeDrains.end()&&it->second.queued&&!it->second.finished) {
|
||||
auto& c=it->second;c.proof.Async(c.batch,c.session,msg->uiSQLErrno!=0);
|
||||
}
|
||||
}
|
||||
// One joint queue: a persistent failing revoke must not starve a different
|
||||
// actor's drain (or vice versa). Keys also distinguish two jobs on one hold.
|
||||
struct Work {uint64_t key;DWORD cookie;bool revoke;};std::vector<Work> work;
|
||||
const auto now=time(nullptr);
|
||||
for(auto it=m_cubeDrains.begin();it!=m_cubeDrains.end();) {
|
||||
const auto cookie=it->first;auto& c=it->second;
|
||||
if(!CubeDrainOwner(c,true)){c.ownerLost=true;if(!c.revocationReason)c.revocationReason=2;}
|
||||
if(!c.began&&(c.ownerLost||now-c.created>=60)){it=m_cubeDrains.erase(it);continue;}++it;
|
||||
if(c.began&&c.revocationReason&&!c.revocationDone&&c.nextRevocation<=now)work.push_back({uint64_t(cookie)*2,cookie,true});
|
||||
if(!c.queued||c.finished||c.nextAttempt>now)continue;
|
||||
if(c.phase=="FIRST"&&!c.asyncQueued)c.asyncQueued=db.CubeAsyncFence(cookie);
|
||||
if(c.proof.Complete())work.push_back({uint64_t(cookie)*2+1,cookie,false});
|
||||
}
|
||||
const auto start=std::upper_bound(work.begin(),work.end(),m_cubeWorkCursor,[](uint64_t key,const Work& item){return key<item.key;});
|
||||
const size_t offset=size_t(start-work.begin());
|
||||
for(size_t n=0;n<work.size()&&n<2;++n) {
|
||||
const auto& item=work[(offset+n)%work.size()];auto& c=m_cubeDrains.find(item.cookie)->second;m_cubeWorkCursor=item.key;
|
||||
if(item.revoke)CubeAuthorityRevoke(c,c.revocationReason);else CubeDrainFinalize(c);
|
||||
}
|
||||
for(auto it=m_cubeDrains.begin();it!=m_cubeDrains.end();) {
|
||||
if(it->second.recovery&&it->second.revocationDone)it=m_cubeDrains.erase(it);else ++it;
|
||||
} // only obsolete in-memory recovery slots retire; SQL holds survive
|
||||
}
|
||||
void CClientManager::CubeDrainFinalize(PortCube::RuntimeDrain& c) {
|
||||
auto& db=CDBManager::instance();
|
||||
// An old DB connection/generation may still have queued callbacks.
|
||||
// Do not let it finalize a drain after authority has moved elsewhere.
|
||||
PortEconomy::Mysql mysql(db.DirectHandle());
|
||||
PortCube::OwnerStore<PortEconomy::Mysql> authority(mysql,[&](uint32_t v){auto p=m_map_itemTableByVnum.find(v);return p==m_map_itemTableByVnum.end()?PortCube::Proto{}:PortCube::Proto{unsigned(p->second->bSize),bool(p->second->dwFlags&ITEM_FLAG_STACKABLE)};});
|
||||
if(!(c.ownerLost?authority.Current(c.ownership.leader):authority.Check(c.batch,c.ownership))){c.nextAttempt=time(nullptr)+5;return;}
|
||||
PortCube::FenceStore<PortEconomy::Mysql> store(mysql,[&](uint32_t v){auto p=m_map_itemTableByVnum.find(v);return p==m_map_itemTableByVnum.end()?PortCube::Proto{}:PortCube::Proto{unsigned(p->second->bSize),bool(p->second->dwFlags&ITEM_FLAG_STACKABLE)};});
|
||||
const bool owner=!c.ownerLost&&db.SQLFenceFailures()==c.router;
|
||||
auto result=store.FinishDrain(c.batch,c.proof,c.session,db.EconomyFailures(false),db.EconomyFailures(true),owner);
|
||||
if(result==PortCube::FenceStore<PortEconomy::Mysql>::Done) {
|
||||
c.finished=true;c.phase=owner&&c.proof.Clean(db.EconomyFailures(false),db.EconomyFailures(true))?"FROZEN":"ABORTED";
|
||||
} else {
|
||||
// FinishDrain may have committed despite a lost COMMIT ACK. Read
|
||||
// its original durable outcome, never infer a downgrade or unlock.
|
||||
PortCube::Batch recovered;std::string phase,image;
|
||||
if(store.Recover(c.batch.account,c.batch.player,recovered,phase,image)==PortCube::FenceStore<PortEconomy::Mysql>::Done&&
|
||||
PortCube::Encode(recovered)==PortCube::Encode(c.batch)&&(phase=="FROZEN"||phase=="ABORTED")) {
|
||||
c.finished=true;c.phase=phase;
|
||||
} else c.nextAttempt=time(nullptr)+5;
|
||||
}
|
||||
// Deliberately retain both FROZEN and ABORTED holds. Settlement/image
|
||||
// application and exact resync ACK must be wired before any release.
|
||||
}
|
||||
|
||||
void CClientManager::CubeHandshakeRequest(CPeer* peer,DWORD handle,const char* data,DWORD length) {
|
||||
PortCube::Handshake f;
|
||||
if(!peer||!peer->GetChannel()||!handle||!PortCube::DecodeHandshake(data,length,f)||PortCube::IsDbHandshakeReply(f.message))return;
|
||||
if(f.message==PortCube::Message::LiveResumeCheckRequest) {
|
||||
if(PortCube::HandshakeEnabled&&PortCube::ActorMutationAuditComplete){CubeLiveResumeCheckRoute(peer,handle,f);return;}
|
||||
f.message=PortCube::Message::LiveResumeCheckAnswer;f.status=PortCube::Status::Held;f.body.clear();
|
||||
const auto bytes=PortCube::EncodeHandshake(f);peer->EncodeHeader(PortCube::HandshakeHeader,handle,bytes.size());peer->Encode(bytes.data(),bytes.size());return;
|
||||
}
|
||||
if(f.message==PortCube::Message::LiveReleaseRequest) {
|
||||
if(PortCube::HandshakeEnabled&&PortCube::ActorMutationAuditComplete){CubeLiveReleaseRoute(peer,handle,f);return;}
|
||||
f.message=PortCube::Message::LiveReleaseAnswer;f.status=PortCube::Status::Held;f.body.clear();
|
||||
const auto bytes=PortCube::EncodeHandshake(f);peer->EncodeHeader(PortCube::HandshakeHeader,handle,bytes.size());peer->Encode(bytes.data(),bytes.size());return;
|
||||
}
|
||||
if(f.message==PortCube::Message::LiveImageAck) {
|
||||
if(PortCube::HandshakeEnabled&&PortCube::ActorMutationAuditComplete){CubeLiveImageAckRoute(peer,handle,f);return;}
|
||||
f.message=PortCube::Message::LiveImageAckAnswer;f.status=PortCube::Status::Held;f.body.clear();
|
||||
const auto bytes=PortCube::EncodeHandshake(f);peer->EncodeHeader(PortCube::HandshakeHeader,handle,bytes.size());peer->Encode(bytes.data(),bytes.size());return;
|
||||
}
|
||||
if(f.message==PortCube::Message::LiveImageRequest) {
|
||||
if(PortCube::HandshakeEnabled&&PortCube::ActorMutationAuditComplete){CubeLiveImageRoute(peer,handle,f);return;}
|
||||
f.message=PortCube::Message::LiveImageAnswer;f.status=PortCube::Status::Held;
|
||||
const auto bytes=PortCube::EncodeHandshake(f);peer->EncodeHeader(PortCube::HandshakeHeader,handle,bytes.size());peer->Encode(bytes.data(),bytes.size());return;
|
||||
}
|
||||
if(f.message==PortCube::Message::Prepare||f.message==PortCube::Message::Execute) {
|
||||
if(PortCube::HandshakeEnabled&&PortCube::ActorMutationAuditComplete){CubeCraftRoute(peer,handle,f);return;}
|
||||
f.message=PortCube::Message::CraftAnswer;f.status=PortCube::Status::Held;
|
||||
const auto bytes=PortCube::EncodeHandshake(f);peer->EncodeHeader(PortCube::HandshakeHeader,handle,bytes.size());peer->Encode(bytes.data(),bytes.size());return;
|
||||
}
|
||||
if(f.message==PortCube::Message::RecoveryClaim||f.message==PortCube::Message::RecoveryImageRequest) {
|
||||
const bool image=f.message==PortCube::Message::RecoveryImageRequest;
|
||||
if(PortCube::HandshakeEnabled&&PortCube::ActorMutationAuditComplete){if(image)CubeRecoveryImageRoute(peer,handle,f);else CubeRecoveryRoute(peer,handle,f);return;}
|
||||
f.message=image?PortCube::Message::RecoveryImageAnswer:PortCube::Message::RecoveryAnswer;f.status=PortCube::Status::Held;
|
||||
const auto bytes=PortCube::EncodeHandshake(f);peer->EncodeHeader(PortCube::HandshakeHeader,handle,bytes.size());peer->Encode(bytes.data(),bytes.size());return;
|
||||
}
|
||||
// Closed at the actual ingress, not merely at a UI button. In particular,
|
||||
// receiving a syntactically valid Arm does not prove the actor was frozen.
|
||||
if(!PortCube::HandshakeEnabled) {
|
||||
f.message=PortCube::Message::Answer;f.status=PortCube::Status::Held;f.body.clear();
|
||||
const auto bytes=PortCube::EncodeHandshake(f);peer->EncodeHeader(PortCube::HandshakeHeader,handle,bytes.size());peer->Encode(bytes.data(),bytes.size());return;
|
||||
}
|
||||
CubeHandshakeRoute(peer,handle,f);
|
||||
}
|
||||
void CClientManager::CubeRecoveryRoute(CPeer* peer,DWORD handle,const PortCube::Handshake& request) {
|
||||
using namespace PortCube;if(!peer||!handle||!peer->GetChannel()||!ValidHandshake(request)||request.message!=Message::RecoveryClaim)return;
|
||||
auto reply=request;reply.message=Message::RecoveryAnswer;reply.status=Status::Held;
|
||||
auto* login=GetLoginDataByAID(request.account);bool member=false;
|
||||
if(login&&!login->IsPlay()&&GetPeer(peer->GetHandle())==peer&&login->GetConnectedPeerHandle()==peer->GetHandle())
|
||||
for(const auto& player:login->GetAccountRef().players)if(player.dwID==request.player)member=true;
|
||||
if(member&&!*GetTablePostfix()) {
|
||||
if(CubeMemoryLoadable(request.account,request.player)&&CubeAccountLoadable(request.account,request.player))reply.status=Status::RecoveryClear;
|
||||
else {
|
||||
OwnerGrant grant;
|
||||
if(CubeRecoveryClaim(peer,handle,request.account,request.player,request.session,grant)) {
|
||||
reply.status=Status::RecoveryGranted;reply.cookie=grant.binding.cookie;reply.epoch=grant.binding.epoch;reply.owner=grant.binding.owner;reply.token=grant.binding.request;reply.body=EncodeOwnerGrant(grant);
|
||||
}
|
||||
}
|
||||
}
|
||||
const auto bytes=EncodeHandshake(reply);if(bytes.empty())return;
|
||||
peer->EncodeHeader(HandshakeHeader,handle,bytes.size());peer->Encode(bytes.data(),bytes.size());
|
||||
}
|
||||
|
||||
void CClientManager::CubeRecoveryImageRoute(CPeer* peer,DWORD handle,const PortCube::Handshake& request) {
|
||||
using namespace PortCube;
|
||||
if(!peer||!peer->GetChannel()||!handle||!ValidHandshake(request)||request.message!=Message::RecoveryImageRequest)return;
|
||||
auto reply=request;reply.message=Message::RecoveryImageAnswer;reply.status=Status::Held;
|
||||
OwnerGrant grant;DecodeOwnerGrant(request.body,grant);auto found=m_cubeDrains.find(request.cookie);
|
||||
if(!*GetTablePostfix()&&found!=m_cubeDrains.end()&&GetPeer(peer->GetHandle())==peer) {
|
||||
const auto& c=found->second;
|
||||
if(c.recovery&&c.peer==peer->GetHandle()&&c.handle==handle&&grant.binding.handle==handle&&SameOwnerGrant(c.ownership,grant)&&CubeDrainOwner(c)) {
|
||||
auto lookup=[&](uint32_t v){auto it=m_map_itemTableByVnum.find(v);return it==m_map_itemTableByVnum.end()?Proto{}:Proto{unsigned(it->second->bSize),bool(it->second->dwFlags&ITEM_FLAG_STACKABLE)};};
|
||||
PortEconomy::Mysql mysql(CDBManager::instance().DirectHandle());OwnerStore<PortEconomy::Mysql> owner(mysql,lookup);FenceStore<PortEconomy::Mysql> fence(mysql,lookup);std::string image;
|
||||
if(fence.Resync(c.batch,image,[&](const std::string& current){return owner.ImageWithin(c.batch,grant,current);})==FenceStore<PortEconomy::Mysql>::Done) {
|
||||
const auto body=EncodeRecoveryImage(grant,image);
|
||||
if(!body.empty()){reply.body=body;reply.status=Status::RecoveryImageReady;}
|
||||
}
|
||||
}
|
||||
}
|
||||
const auto bytes=EncodeHandshake(reply);if(bytes.empty())return;peer->EncodeHeader(HandshakeHeader,handle,bytes.size());peer->Encode(bytes.data(),bytes.size());
|
||||
}
|
||||
|
||||
void CClientManager::CubeCraftRoute(CPeer* peer,DWORD handle,const PortCube::Handshake& request) {
|
||||
using namespace PortCube;
|
||||
if(!peer||!peer->GetChannel()||!handle||!ValidHandshake(request)||(request.message!=Message::Prepare&&request.message!=Message::Execute))return;
|
||||
auto reply=request;reply.message=Message::CraftAnswer;reply.status=Status::Held;
|
||||
auto found=m_cubeDrains.find(request.cookie);
|
||||
if(!*GetTablePostfix()&&found!=m_cubeDrains.end()&&GetPeer(peer->GetHandle())==peer) {
|
||||
const auto& c=found->second;
|
||||
if(!c.recovery&&c.queued&&c.finished&&c.phase=="FROZEN"&&c.peer==peer->GetHandle()&&c.handle==handle&&c.session==request.session&&
|
||||
c.batch.account==request.account&&c.batch.player==request.player&&c.batch.epoch==request.epoch&&c.batch.owner==request.owner&&c.batch.token==request.token&&CubeDrainOwner(c)) {
|
||||
auto lookup=[&](uint32_t v){auto it=m_map_itemTableByVnum.find(v);return it==m_map_itemTableByVnum.end()?Proto{}:Proto{unsigned(it->second->bSize),bool(it->second->dwFlags&ITEM_FLAG_STACKABLE)};};
|
||||
PortEconomy::Mysql mysql(CDBManager::instance().DirectHandle());OwnerStore<PortEconomy::Mysql> owner(mysql,lookup);BatchStore<PortEconomy::Mysql> store(mysql,lookup);
|
||||
if(request.message==Message::Prepare) {
|
||||
CraftEntropy entropy;
|
||||
if(store.Prepare(c.batch,[&](){return entropy.Draw();},[&](){return owner.CraftWithin(c.batch,c.ownership);})==BatchStore<PortEconomy::Mysql>::Prepared)reply.status=Status::Prepared;
|
||||
} else {
|
||||
BatchStore<PortEconomy::Mysql>::Receipt result;
|
||||
if(store.Execute(c.batch.token,c.batch.account,c.batch.player,result,[&](const Batch& saved){return Encode(saved)==Encode(c.batch)&&owner.CraftWithin(saved,c.ownership);})==BatchStore<PortEconomy::Mysql>::Complete) {
|
||||
CraftReceipt receipt{result.result,result.successes,result.fee,result.awards};reply.body=EncodeCraftReceipt(receipt);if(!reply.body.empty())reply.status=Status::Complete;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const auto bytes=EncodeHandshake(reply);if(bytes.empty())return;peer->EncodeHeader(HandshakeHeader,handle,bytes.size());peer->Encode(bytes.data(),bytes.size());
|
||||
}
|
||||
|
||||
void CClientManager::CubeLiveImageRoute(CPeer* peer,DWORD handle,const PortCube::Handshake& request) {
|
||||
using namespace PortCube;
|
||||
if(!peer||!peer->GetChannel()||!handle||!ValidHandshake(request)||request.message!=Message::LiveImageRequest)return;
|
||||
auto reply=request;reply.message=Message::LiveImageAnswer;reply.status=Status::Held;
|
||||
auto found=m_cubeDrains.find(request.cookie);
|
||||
if(!*GetTablePostfix()&&found!=m_cubeDrains.end()&&GetPeer(peer->GetHandle())==peer) {
|
||||
auto& c=found->second;
|
||||
if(!c.recovery&&c.queued&&c.finished&&(c.phase=="FROZEN"||c.phase=="RESYNC")&&c.peer==peer->GetHandle()&&c.handle==handle&&c.session==request.session&&
|
||||
c.batch.account==request.account&&c.batch.player==request.player&&c.batch.epoch==request.epoch&&c.batch.owner==request.owner&&c.batch.token==request.token&&CubeDrainOwner(c)) {
|
||||
auto lookup=[&](uint32_t v){auto it=m_map_itemTableByVnum.find(v);return it==m_map_itemTableByVnum.end()?Proto{}:Proto{unsigned(it->second->bSize),bool(it->second->dwFlags&ITEM_FLAG_STACKABLE)};};
|
||||
PortEconomy::Mysql mysql(CDBManager::instance().DirectHandle());OwnerStore<PortEconomy::Mysql> owner(mysql,lookup);FenceStore<PortEconomy::Mysql> fence(mysql,lookup);GoldIntentStore<PortEconomy::Mysql> gold(mysql,lookup);
|
||||
std::vector<GoldIntent> pending;bool credited=gold.Pending(c.batch,pending)==GoldIntentStore<PortEconomy::Mysql>::Stored;
|
||||
for(size_t n=0;credited&&n<std::min(size_t(2),pending.size());++n) {
|
||||
typename GoldIntentStore<PortEconomy::Mysql>::Receipt receipt;
|
||||
credited=gold.Apply(pending[n].event,c.batch.account,c.batch.player,receipt,[&](const GoldIntent& intent){return Matches(intent,c.batch)&&owner.CraftWithin(c.batch,c.ownership);})==GoldIntentStore<PortEconomy::Mysql>::Applied;
|
||||
}
|
||||
std::string image;
|
||||
if(credited&&pending.size()<=2&&fence.Resync(c.batch,image,[&](const std::string& current){return owner.LiveImageWithin(c.batch,c.ownership,current);})==FenceStore<PortEconomy::Mysql>::Done) {
|
||||
reply.body=std::move(image);reply.status=Status::LiveImageReady;c.phase="RESYNC";
|
||||
}
|
||||
}
|
||||
}
|
||||
const auto bytes=EncodeHandshake(reply);if(bytes.empty())return;peer->EncodeHeader(HandshakeHeader,handle,bytes.size());peer->Encode(bytes.data(),bytes.size());
|
||||
}
|
||||
|
||||
void CClientManager::CubeLiveImageAckRoute(CPeer* peer,DWORD handle,const PortCube::Handshake& request) {
|
||||
using namespace PortCube;
|
||||
if(!peer||!peer->GetChannel()||!handle||!ValidHandshake(request)||request.message!=Message::LiveImageAck)return;
|
||||
auto reply=request;reply.message=Message::LiveImageAckAnswer;reply.status=Status::Held;reply.body.clear();
|
||||
const auto found=m_cubeDrains.find(request.cookie);
|
||||
if(!*GetTablePostfix()&&found!=m_cubeDrains.end()&&GetPeer(peer->GetHandle())==peer) {
|
||||
const auto& c=found->second;
|
||||
if(!c.recovery&&c.queued&&c.finished&&c.phase=="RESYNC"&&c.peer==peer->GetHandle()&&c.handle==handle&&c.session==request.session&&
|
||||
c.batch.account==request.account&&c.batch.player==request.player&&c.batch.epoch==request.epoch&&c.batch.owner==request.owner&&c.batch.token==request.token&&CubeDrainOwner(c)) {
|
||||
auto lookup=[&](uint32_t v){auto it=m_map_itemTableByVnum.find(v);return it==m_map_itemTableByVnum.end()?Proto{}:Proto{unsigned(it->second->bSize),bool(it->second->dwFlags&ITEM_FLAG_STACKABLE)};};
|
||||
PortEconomy::Mysql mysql(CDBManager::instance().DirectHandle());ImageAckStore<PortEconomy::Mysql> ack(mysql,lookup);
|
||||
if(ack.AcknowledgeLive(c.batch,c.ownership,request.body)==ImageAckStore<PortEconomy::Mysql>::Stored) {
|
||||
reply.status=Status::LiveImageAcknowledged;reply.body=request.body;
|
||||
}
|
||||
}
|
||||
}
|
||||
const auto bytes=EncodeHandshake(reply);if(bytes.empty())return;peer->EncodeHeader(HandshakeHeader,handle,bytes.size());peer->Encode(bytes.data(),bytes.size());
|
||||
}
|
||||
|
||||
void CClientManager::CubeLiveReleaseRoute(CPeer* peer,DWORD handle,const PortCube::Handshake& request) {
|
||||
using namespace PortCube;
|
||||
if(!peer||!peer->GetChannel()||!handle||!ValidHandshake(request)||request.message!=Message::LiveReleaseRequest)return;
|
||||
auto reply=request;reply.message=Message::LiveReleaseAnswer;reply.status=Status::Held;reply.body.clear();
|
||||
const auto found=m_cubeDrains.find(request.cookie);
|
||||
if(!*GetTablePostfix()&&found!=m_cubeDrains.end()&&GetPeer(peer->GetHandle())==peer) {
|
||||
auto& c=found->second;
|
||||
if(!c.recovery&&c.queued&&c.finished&&(c.phase=="RESYNC"||c.phase=="RELEASED")&&c.peer==peer->GetHandle()&&c.handle==handle&&c.session==request.session&&
|
||||
c.batch.account==request.account&&c.batch.player==request.player&&c.batch.epoch==request.epoch&&c.batch.owner==request.owner&&c.batch.token==request.token&&CubeDrainOwner(c)) {
|
||||
auto lookup=[&](uint32_t v){auto it=m_map_itemTableByVnum.find(v);return it==m_map_itemTableByVnum.end()?Proto{}:Proto{unsigned(it->second->bSize),bool(it->second->dwFlags&ITEM_FLAG_STACKABLE)};};
|
||||
PortEconomy::Mysql mysql(CDBManager::instance().DirectHandle());ReleaseStore<PortEconomy::Mysql> release(mysql,lookup);
|
||||
if(release.ReleaseLive(c.batch,c.ownership,request.body)==ReleaseStore<PortEconomy::Mysql>::Released) {
|
||||
c.phase="RELEASED";c.revocationDone=true;reply.status=Status::LiveReleased;reply.body=request.body;
|
||||
}
|
||||
}
|
||||
}
|
||||
const auto bytes=EncodeHandshake(reply);if(bytes.empty())return;peer->EncodeHeader(HandshakeHeader,handle,bytes.size());peer->Encode(bytes.data(),bytes.size());
|
||||
}
|
||||
|
||||
void CClientManager::CubeLiveResumeCheckRoute(CPeer* peer,DWORD handle,const PortCube::Handshake& request) {
|
||||
using namespace PortCube;
|
||||
if(!peer||!peer->GetChannel()||!handle||!ValidHandshake(request)||request.message!=Message::LiveResumeCheckRequest)return;
|
||||
auto reply=request;reply.message=Message::LiveResumeCheckAnswer;reply.status=Status::Held;reply.body.clear();
|
||||
const auto found=m_cubeDrains.find(request.cookie);
|
||||
if(!*GetTablePostfix()&&found!=m_cubeDrains.end()&&GetPeer(peer->GetHandle())==peer) {
|
||||
const auto& c=found->second;
|
||||
if(!c.recovery&&c.queued&&c.finished&&c.phase=="RELEASED"&&c.revocationDone&&c.peer==peer->GetHandle()&&c.handle==handle&&c.session==request.session&&
|
||||
c.batch.account==request.account&&c.batch.player==request.player&&c.batch.epoch==request.epoch&&c.batch.owner==request.owner&&c.batch.token==request.token&&CubeDrainOwner(c)) {
|
||||
auto lookup=[&](uint32_t v){auto it=m_map_itemTableByVnum.find(v);return it==m_map_itemTableByVnum.end()?Proto{}:Proto{unsigned(it->second->bSize),bool(it->second->dwFlags&ITEM_FLAG_STACKABLE)};};
|
||||
PortEconomy::Mysql mysql(CDBManager::instance().DirectHandle());ReleaseStore<PortEconomy::Mysql> release(mysql,lookup);
|
||||
if(release.CheckResumeLive(c.batch,c.ownership,request.body)==ReleaseStore<PortEconomy::Mysql>::Checked){reply.status=Status::LiveResumeChecked;reply.body=request.body;}
|
||||
}
|
||||
}
|
||||
// Read-only preflight: no context erasure, save/load grant or actor thaw.
|
||||
const auto bytes=EncodeHandshake(reply);if(bytes.empty())return;peer->EncodeHeader(HandshakeHeader,handle,bytes.size());peer->Encode(bytes.data(),bytes.size());
|
||||
}
|
||||
|
||||
void CClientManager::CubeHandshakeRoute(CPeer* peer,DWORD handle,const PortCube::Handshake& f) {
|
||||
using namespace PortCube;
|
||||
if(f.message==Message::LiveResumeCheckRequest){CubeLiveResumeCheckRoute(peer,handle,f);return;}
|
||||
if(f.message==Message::LiveReleaseRequest){CubeLiveReleaseRoute(peer,handle,f);return;}
|
||||
if(f.message==Message::LiveImageAck){CubeLiveImageAckRoute(peer,handle,f);return;}
|
||||
if(f.message==Message::LiveImageRequest){CubeLiveImageRoute(peer,handle,f);return;}
|
||||
if(f.message==Message::Prepare||f.message==Message::Execute){CubeCraftRoute(peer,handle,f);return;}
|
||||
if(f.message==Message::RecoveryClaim){CubeRecoveryRoute(peer,handle,f);return;}
|
||||
if(f.message==Message::RecoveryImageRequest){CubeRecoveryImageRoute(peer,handle,f);return;}
|
||||
if(!peer||!handle||!peer->GetChannel()||!ValidHandshake(f)||IsDbHandshakeReply(f.message))return;
|
||||
RuntimeDrain binding;binding.batch.account=f.account;binding.batch.player=f.player;binding.peer=peer->GetHandle();
|
||||
if(!CubeDrainOwner(binding))return; // authenticated core AND current account ownership
|
||||
auto send=[&](Status status,DWORD cookie) {
|
||||
Handshake reply=f;reply.message=Message::Answer;reply.status=status;reply.cookie=cookie;reply.body.clear();
|
||||
const auto bytes=EncodeHandshake(reply);if(bytes.empty())return;
|
||||
peer->EncodeHeader(HandshakeHeader,handle,bytes.size());peer->Encode(bytes.data(),bytes.size());
|
||||
};
|
||||
auto matches=[&](const RuntimeDrain& c) {
|
||||
return c.peer==peer->GetHandle()&&c.handle==handle&&c.session==f.session&&c.batch.account==f.account&&c.batch.player==f.player&&
|
||||
c.batch.epoch==f.epoch&&c.batch.owner==f.owner&&c.batch.token==f.token;
|
||||
};
|
||||
auto status=[&](const RuntimeDrain& c) {
|
||||
if(c.cancelled)return Status::Cancelled;
|
||||
if(!CubeDrainOwner(c))return Status::Held;
|
||||
if(c.finished)return c.phase=="FROZEN"?Status::Frozen:c.phase=="ABORTED"?Status::Aborted:Status::Held;
|
||||
if(c.queued)return Status::Draining;
|
||||
return c.began?Status::Held:Status::Armed;
|
||||
};
|
||||
if(f.message==Message::Arm) {
|
||||
for(const auto& entry:m_cubeDrains)if(matches(entry.second)) {
|
||||
// Exact retry returns the original cookie; changed body is not a
|
||||
// second Arm and must not release or replace the first hold.
|
||||
send(Encode(entry.second.batch)==f.body&&CubeAuthorityCheck(entry.second,entry.second.queued)?status(entry.second):Status::Held,entry.first);return;
|
||||
}
|
||||
Batch b;if(!Decode(f.body,b))return;
|
||||
const auto cookie=CubeDrainArm(peer,handle,f.session,b);
|
||||
send(cookie?Status::Armed:Status::Held,cookie);return;
|
||||
}
|
||||
auto it=m_cubeDrains.find(f.cookie);
|
||||
if(it==m_cubeDrains.end()||!matches(it->second)){send(Status::Held,f.cookie);return;}
|
||||
auto& c=it->second;
|
||||
if(c.cancelled){send(Status::Cancelled,f.cookie);return;}
|
||||
if(!CubeAuthorityCheck(c,c.queued)){c.ownerLost=true;send(Status::Held,f.cookie);return;}
|
||||
if(f.message==Message::GoldClose) {
|
||||
if(!c.began||!CubeDrainOwner(c)){send(Status::Held,f.cookie);return;}
|
||||
GoldSourceSeal seal;static_cast<GoldSourceBinding&>(seal)=GoldSourceFor(c.batch,f.session,f.cookie,handle);
|
||||
if(!DecodeGoldManifest(f.body,seal.events))return;
|
||||
auto& db=CDBManager::instance();PortEconomy::Mysql mysql(db.DirectHandle());
|
||||
OwnerStore<PortEconomy::Mysql> authority(mysql,[&](uint32_t v){auto p=m_map_itemTableByVnum.find(v);return p==m_map_itemTableByVnum.end()?Proto{}:Proto{unsigned(p->second->bSize),bool(p->second->dwFlags&ITEM_FLAG_STACKABLE)};});
|
||||
if(!authority.Check(c.batch,c.ownership)){send(Status::Held,f.cookie);return;}
|
||||
GoldIntentStore<PortEconomy::Mysql> store(mysql,[&](uint32_t v){auto p=m_map_itemTableByVnum.find(v);return p==m_map_itemTableByVnum.end()?Proto{}:Proto{unsigned(p->second->bSize),bool(p->second->dwFlags&ITEM_FLAG_STACKABLE)};});
|
||||
if(store.CloseSource(c.batch,seal)!=GoldIntentStore<PortEconomy::Mysql>::Stored){send(Status::Held,f.cookie);return;}
|
||||
auto reply=f;reply.message=Message::GoldCloseAck;reply.status=Status::GoldClosed;const auto bytes=EncodeHandshake(reply);
|
||||
if(bytes.empty())return;peer->EncodeHeader(HandshakeHeader,handle,bytes.size());peer->Encode(bytes.data(),bytes.size());return;
|
||||
}
|
||||
if(f.message==Message::GoldEnqueue) {
|
||||
// Original authenticated peer/login/handle/session/cookie AND immutable
|
||||
// batch, not a client-provided amount on an unowned player. DB restart
|
||||
// loses this binding: keep the source outbox pending, never adopt it.
|
||||
GoldIntent i;
|
||||
if(!c.began||!CubeDrainOwner(c)||!DecodeGoldIntent(f.body,i)||!Matches(i,c.batch)){send(Status::Held,f.cookie);return;}
|
||||
auto& db=CDBManager::instance();PortEconomy::Mysql mysql(db.DirectHandle());
|
||||
OwnerStore<PortEconomy::Mysql> authority(mysql,[&](uint32_t v){auto p=m_map_itemTableByVnum.find(v);return p==m_map_itemTableByVnum.end()?Proto{}:Proto{unsigned(p->second->bSize),bool(p->second->dwFlags&ITEM_FLAG_STACKABLE)};});
|
||||
if(!authority.Check(c.batch,c.ownership)){send(Status::Held,f.cookie);return;}
|
||||
GoldIntentStore<PortEconomy::Mysql> store(mysql,[&](uint32_t v){auto p=m_map_itemTableByVnum.find(v);return p==m_map_itemTableByVnum.end()?Proto{}:Proto{unsigned(p->second->bSize),bool(p->second->dwFlags&ITEM_FLAG_STACKABLE)};});
|
||||
const auto result=store.Enqueue(c.batch,i);
|
||||
if(result!=GoldIntentStore<PortEconomy::Mysql>::Stored&&result!=GoldIntentStore<PortEconomy::Mysql>::Applied){send(Status::Held,f.cookie);return;}
|
||||
auto reply=f;reply.message=Message::GoldAck;reply.status=result==GoldIntentStore<PortEconomy::Mysql>::Stored?Status::GoldStored:Status::GoldApplied;
|
||||
const auto bytes=EncodeHandshake(reply);if(bytes.empty())return;
|
||||
peer->EncodeHeader(HandshakeHeader,handle,bytes.size());peer->Encode(bytes.data(),bytes.size());return;
|
||||
}
|
||||
if(f.message==Message::Invalidate) {
|
||||
// Sticky poison. Never turn an invalidated actor snapshot into a clean
|
||||
// FROZEN proof, even if its ordinary values later return to the same bytes.
|
||||
c.ownerLost=true;
|
||||
if(c.began) {
|
||||
auto& db=CDBManager::instance();PortEconomy::Mysql mysql(db.DirectHandle());
|
||||
FenceStore<PortEconomy::Mysql> store(mysql,[&](uint32_t v){auto p=m_map_itemTableByVnum.find(v);return p==m_map_itemTableByVnum.end()?Proto{}:Proto{unsigned(p->second->bSize),bool(p->second->dwFlags&ITEM_FLAG_STACKABLE)};});
|
||||
// The store refuses to abort an already accepted/ambiguous Prepare.
|
||||
// Retain that hold for receipt recovery instead of inventing refunds.
|
||||
if(store.AbortUnprepared(c.batch)==FenceStore<PortEconomy::Mysql>::Done)c.phase="ABORTED";
|
||||
}
|
||||
send(Status::Held,f.cookie);return;
|
||||
}
|
||||
if(f.message==Message::Cancel) {
|
||||
// No SQL Begin attempt: no accepted/ambiguous durable ownership exists.
|
||||
// Keep a short tombstone so lost cancellation ACK can be replayed.
|
||||
if(!c.began&&!c.ownerLost){c.cancelled=true;c.created=time(nullptr);send(Status::Cancelled,f.cookie);}
|
||||
else send(Status::Held,f.cookie);
|
||||
return;
|
||||
}
|
||||
if(f.message==Message::Submit&&!c.finished&&!c.queued)CubeDrainSubmit(peer,handle,f.session,f.cookie);
|
||||
send(status(c),f.cookie); // Submit refusal is a hold, never an unlock ACK
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include "../../common/cube_drain.h"
|
||||
#include "../../common/cube_handshake.h"
|
||||
#include "../../common/cube_owner_types.h"
|
||||
#include <ctime>
|
||||
|
||||
namespace PortCube {
|
||||
// Internal DB adapter. Header78 dispatch is compiled but ingress is hard-gated
|
||||
// off in cube_handshake.h. A game coordinator MUST quiesce the actor before Arm,
|
||||
// send final saves after Arm ACK, and submit on the same peer FIFO. These APIs
|
||||
// and the game preparation state machine do not themselves stop asset events.
|
||||
constexpr int MainFirst=101,MainSecond=102;
|
||||
struct RuntimeDrain {
|
||||
Batch batch;Drain proof;
|
||||
uint64_t session=0,main=0,async=0,router=0;
|
||||
uint32_t peer=0,handle=0;
|
||||
bool began=false,queued=false,asyncQueued=false,ownerLost=false,finished=false,cancelled=false;
|
||||
std::time_t created=0,nextAttempt=0;
|
||||
std::string phase;
|
||||
OwnerGrant ownership;
|
||||
bool revocationDone=false;
|
||||
unsigned revocationReason=0; // trusted peer/account lifecycle, not Invalidate
|
||||
bool recovery=false; // held pre-load adoption, not a playing actor
|
||||
std::time_t nextRevocation=0;
|
||||
};
|
||||
}
|
||||
@@ -52,6 +52,7 @@ void CDBManager::Clear()
|
||||
}
|
||||
}
|
||||
|
||||
PortSQLFence::PlayerRouter().Clear();
|
||||
Initialize();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <mysql/mysql.h>
|
||||
|
||||
#include "../../libsql/AsyncSQL.h"
|
||||
#include "SQLFences.h"
|
||||
|
||||
#define SQL_SAFE_LENGTH(size) (size * 2 + 1)
|
||||
#define QUERY_SAFE_LENGTH(size) (1024 + SQL_SAFE_LENGTH(size))
|
||||
@@ -46,8 +47,11 @@ class CDBManager : public singleton<CDBManager>
|
||||
|
||||
void ReturnQuery(const char * c_pszQuery, int iType, DWORD dwIdent, void * pvData, int iSlot = SQL_PLAYER);
|
||||
void AsyncQuery(const char * c_pszQuery, int iSlot = SQL_PLAYER);
|
||||
void EconomyAsyncFence(DWORD pid) { m_asyncSQL[SQL_PLAYER]->ReturnQuery("SELECT 1",reinterpret_cast<void*>(static_cast<uintptr_t>(pid))); }
|
||||
SQLMsg* PopEconomyAsyncFence() { SQLMsg* message=nullptr;return m_asyncSQL[SQL_PLAYER]->PopResult(&message)?message:nullptr; }
|
||||
bool EconomyAsyncFence(DWORD pid) { return PortSQLFence::Queue(m_asyncSQL[SQL_PLAYER],PortSQLFence::Economy,pid); }
|
||||
SQLMsg* PopEconomyAsyncFence() { return PortSQLFence::Pop(m_asyncSQL[SQL_PLAYER],PortSQLFence::Economy); }
|
||||
bool CubeAsyncFence(DWORD cookie) { return PortSQLFence::Queue(m_asyncSQL[SQL_PLAYER],PortSQLFence::Cube,cookie); }
|
||||
SQLMsg* PopCubeAsyncFence() { return PortSQLFence::Pop(m_asyncSQL[SQL_PLAYER],PortSQLFence::Cube); }
|
||||
uint64_t SQLFenceFailures() { return PortSQLFence::PlayerRouter().Failures(); }
|
||||
uint64_t EconomyFailures(bool async) { return (async?m_asyncSQL[SQL_PLAYER]:m_mainSQL[SQL_PLAYER])->FailureEpoch(); }
|
||||
MYSQL* DirectHandle(int slot=SQL_PLAYER) { return m_directSQL[slot]->GetSQLHandle(); }
|
||||
SQLMsg * DirectQuery(const char * c_pszQuery, int iSlot = SQL_PLAYER);
|
||||
|
||||
@@ -56,6 +56,7 @@ void CClientManager::EconomyRequest(CPeer* peer,DWORD handle,const char* data,DW
|
||||
if(mysql.Query("SELECT amount FROM port_economy_credit WHERE pid="+std::to_string(r.player),rows))send("Unclaimed proceeds: "+(rows.empty()?std::string("0"):rows[0][0]),true);
|
||||
return;
|
||||
}
|
||||
if(!CubeMemoryLoadable(r.account,r.player)||!CubePlayerWritable(r.player)){send("Character assets are awaiting Cube reconciliation.",false);return;}
|
||||
if(r.operation==PortEconomy::List) {
|
||||
auto it=m_map_itemTableByVnum.find(r.itemVnum);
|
||||
if(it==m_map_itemTableByVnum.end() || (it->second->dwAntiFlags&(ITEM_ANTIFLAG_GIVE|ITEM_ANTIFLAG_MYSHOP)) || it->second->bType==ITEM_QUEST) {send("This item cannot be listed.",false);return;}
|
||||
@@ -74,6 +75,8 @@ void CClientManager::EconomyRequest(CPeer* peer,DWORD handle,const char* data,DW
|
||||
}
|
||||
|
||||
bool CClientManager::EconomyBeforeLoad(CPeer* peer,DWORD handle,TPlayerLoadPacket* packet) {
|
||||
if(!CubeMemoryLoadable(packet->account_id,packet->player_id))return false;
|
||||
if(!CubeAccountLoadable(packet->account_id,packet->player_id))return false;
|
||||
if(*GetTablePostfix())return true;
|
||||
const int installed=schema();if(installed==0)return true;if(installed<0)return false;
|
||||
// Existing ownership checks must run before evicting or fencing any cache.
|
||||
@@ -90,6 +93,7 @@ bool CClientManager::EconomyBeforeLoad(CPeer* peer,DWORD handle,TPlayerLoadPacke
|
||||
auto epoch=m_economyEnqueueEpoch.find(packet->player_id);
|
||||
fence.mainFailures=epoch==m_economyEnqueueEpoch.end()?database.EconomyFailures(false):epoch->second.first;
|
||||
fence.asyncFailures=epoch==m_economyEnqueueEpoch.end()?database.EconomyFailures(true):epoch->second.second;
|
||||
fence.routerFailures=database.SQLFenceFailures();
|
||||
m_economyFences[packet->player_id]=fence;
|
||||
// Eviction sends every dirty snapshot before the two FIFO barriers. Never
|
||||
// settle on a cached player, including caches still awaiting logout timeout.
|
||||
@@ -107,11 +111,13 @@ void CClientManager::EconomyMainFence(DWORD pid,bool failed) {
|
||||
// A second main barrier and an async barrier follow those callbacks.
|
||||
it->second.primed=true;
|
||||
CDBManager::instance().ReturnQuery("SELECT 1",QID_ECONOMY_FENCE,pid,nullptr);
|
||||
CDBManager::instance().EconomyAsyncFence(pid);
|
||||
it->second.asyncQueued=CDBManager::instance().EconomyAsyncFence(pid);
|
||||
} else it->second.mainDone=true;
|
||||
}
|
||||
void CClientManager::EconomyTick() {
|
||||
auto& database=CDBManager::instance();
|
||||
for(auto& entry:m_economyFences)if(entry.second.primed&&!entry.second.asyncQueued)
|
||||
entry.second.asyncQueued=database.EconomyAsyncFence(entry.first);
|
||||
while(SQLMsg* raw=database.PopEconomyAsyncFence()) {
|
||||
Query q(raw);DWORD pid=static_cast<DWORD>(reinterpret_cast<uintptr_t>(q->pvUserData));
|
||||
auto it=m_economyFences.find(pid);if(it!=m_economyFences.end()){it->second.asyncDone=true;it->second.failed|=q->uiSQLErrno!=0;}
|
||||
@@ -121,10 +127,10 @@ void CClientManager::EconomyTick() {
|
||||
if(fence.nextAttempt>time(nullptr)){++it;continue;}
|
||||
if(!fence.mainDone||!fence.asyncDone){++it;continue;}
|
||||
auto* login=GetLoginDataByAID(fence.account);
|
||||
if(login&&login->IsPlay()){++it;continue;}
|
||||
if((login&&login->IsPlay())||!CubeMemoryLoadable(fence.account,it->first)||!CubePlayerWritable(it->first)){++it;continue;}
|
||||
PortEconomy::Mysql mysql(database.DirectHandle());
|
||||
PortEconomy::Store<PortEconomy::Mysql> store(mysql,[&](uint32_t vnum){auto p=m_map_itemTableByVnum.find(vnum);return p==m_map_itemTableByVnum.end()?0u:unsigned(p->second->bSize);});
|
||||
const bool failed=fence.failed||database.EconomyFailures(false)!=fence.mainFailures||database.EconomyFailures(true)!=fence.asyncFailures;
|
||||
const bool failed=fence.failed||database.EconomyFailures(false)!=fence.mainFailures||database.EconomyFailures(true)!=fence.asyncFailures||database.SQLFenceFailures()!=fence.routerFailures;
|
||||
bool done=failed?store.Abort(it->first,fence.account):store.Settle(it->first,fence.account)!=PortEconomy::Store<PortEconomy::Mysql>::Retry;
|
||||
if(done) {
|
||||
m_economyEnqueueEpoch.erase(it->first);
|
||||
@@ -136,11 +142,14 @@ void CClientManager::EconomyTick() {
|
||||
}
|
||||
|
||||
bool CClientManager::EconomySaveAllowed(CPeer* peer,DWORD pid) {
|
||||
if(!CubePeerMaySave(peer,pid))return false;
|
||||
if(!CubePlayerWritable(pid))return false;
|
||||
if(m_economyClosed.count(pid))return false;
|
||||
auto it=m_economyOwners.find(pid);if(it==m_economyOwners.end())return true;
|
||||
return owns(GetLoginDataByAID(it->second),peer,pid,true);
|
||||
}
|
||||
bool CClientManager::EconomyItemWritable(DWORD id) {
|
||||
if(!CubeItemWritable(id))return false;
|
||||
if(*GetTablePostfix())return true;
|
||||
const int installed=schema();if(installed==0)return true;if(installed<0)return false;
|
||||
auto q=query("SELECT id FROM port_economy_custody WHERE id="+std::to_string(id));
|
||||
@@ -152,6 +161,8 @@ bool CClientManager::EconomyItemWritable(DWORD id) {
|
||||
// or a migrated catalogue outside the tables that legacy deletion cleans up.
|
||||
// Catalogue users need an explicit audited retirement, not an implicit reset.
|
||||
bool CClientManager::EconomyCanDelete(DWORD pid) {
|
||||
if(!CubeMemoryLoadable(0,pid))return false;
|
||||
if(!CubePlayerWritable(pid))return false;
|
||||
if(*GetTablePostfix())return true;
|
||||
const int installed=schema();if(installed==0)return true;if(installed<0)return false;
|
||||
if(m_economyFences.count(pid)||m_economyClosed.count(pid))return false;
|
||||
|
||||
@@ -112,7 +112,16 @@ bool CItemIDRangeManager::BuildRange(DWORD dwMin, DWORD dwMax, TItemIDRangeTable
|
||||
std::string sources="SELECT id FROM item"+bounds;
|
||||
if(hasLegacy)sources+=" UNION ALL SELECT id FROM offline_shop_item"+bounds;
|
||||
if(valid)sources+=" UNION ALL SELECT id FROM port_economy_custody"+bounds+" UNION ALL SELECT id FROM port_economy_item_reservations"+bounds;
|
||||
snprintf(szQuery,sizeof(szQuery),"SELECT MAX(id) FROM (%s) AS allocated_ids",sources.c_str());
|
||||
// PORT: a durable Cube drain may hold dirty cached IDs that are not in
|
||||
// item yet. They must not be reissued while that owner awaits resync.
|
||||
auto* cube=CDBManager::instance().DirectQuery("SELECT COUNT(*) FROM information_schema.tables WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='port_cube_item_fences'");
|
||||
if(!cube||cube->uiSQLErrno||!cube->Get()||cube->Get()->uiNumRows!=1||!cube->Get()->pSQLResult){delete cube;return false;}
|
||||
row=mysql_fetch_row(cube->Get()->pSQLResult);
|
||||
const bool hasCube=row&&row[0]&&!strcmp(row[0],"1"),noCube=row&&row[0]&&!strcmp(row[0],"0");
|
||||
delete cube;if(!hasCube&&!noCube)return false;
|
||||
if(hasCube)sources+=" UNION ALL SELECT id FROM port_cube_item_fences"+bounds;
|
||||
const int length=snprintf(szQuery,sizeof(szQuery),"SELECT MAX(id) FROM (%s) AS allocated_ids",sources.c_str());
|
||||
if(length<0||size_t(length)>=sizeof(szQuery))return false;
|
||||
}
|
||||
pMsg = CDBManager::instance().DirectQuery(szQuery);
|
||||
if(!pMsg || pMsg->uiSQLErrno || !pMsg->Get() || pMsg->Get()->uiNumRows!=1 || !pMsg->Get()->pSQLResult){delete pMsg;return false;}
|
||||
|
||||
+35
-15
@@ -1,28 +1,29 @@
|
||||
MAKE = gmake
|
||||
CC = clang++-devel
|
||||
MAKE = make
|
||||
CC ?= clang++-devel
|
||||
|
||||
INCDIR =
|
||||
LIBDIR =
|
||||
BINDIR = ..
|
||||
OBJDIR = .obj
|
||||
DBDIR = /usr/metin2/server/share/bin
|
||||
DBDIR ?= ../../share/bin
|
||||
|
||||
GCC_VERSION = $(shell $(CC) --version 2>&1 | grep "(GCC)" | cut -d' ' -f3 | cut -d'.' -f1)
|
||||
BSD_VERSION = $(shell uname -v 2>&1 | cut -d' ' -f2 | cut -d'.' -f1)
|
||||
UNAME_S := $(shell uname -s)
|
||||
SVN_VERSION = 40142
|
||||
$(shell if [ ! -d $(OBJDIR) ]; then mkdir $(OBJDIR); fi)
|
||||
|
||||
# TARGET = $(BINDIR)/db_r$(SVN_VERSION)
|
||||
TARGET = $(BINDIR)/db
|
||||
|
||||
CFLAGS = -g -Wall -w -O2 -pipe -fno-rtti -std=c++2b -fno-exceptions -pthread -D_THREAD_SAFE
|
||||
CFLAGS += -mtune=i686
|
||||
|
||||
ifeq ($(UNAME_S), Linux)
|
||||
CFLAGS ?= -g -Wall -w -O2 -pipe -fno-rtti -std=c++2b -fno-exceptions -pthread -D_THREAD_SAFE
|
||||
LIBS += -lmariadb -lz -lssl -lcrypto -ldl
|
||||
INCDIR += -I/usr/include/mariadb -I/usr/include/mysql
|
||||
else
|
||||
CFLAGS ?= -g -Wall -w -O2 -pipe -fno-rtti -std=c++2b -fno-exceptions -pthread -D_THREAD_SAFE -mtune=i686
|
||||
# MySQL
|
||||
LIBS += /usr/local/lib/mysql/libmysqlclient.a /usr/lib/libz.a
|
||||
|
||||
# OpenSSL
|
||||
LIBS += /usr/lib/libssl.a /usr/lib/libcrypto.a
|
||||
endif
|
||||
|
||||
# Miscellaneous external libraries
|
||||
INCDIR += -I../../../extern/include
|
||||
@@ -39,7 +40,7 @@ SRCS = Config.cpp NetBase.cpp Peer.cpp PeerBase.cpp Main.cpp Lock.cpp DBManager.
|
||||
ClientManagerBoot.cpp ClientManagerParty.cpp ClientManagerGuild.cpp GuildManager.cpp HB.cpp \
|
||||
PrivManager.cpp MoneyLog.cpp ItemAwardManager.cpp ClientManagerEventFlag.cpp Marriage.cpp \
|
||||
Monarch.cpp BlockCountry.cpp ItemIDRangeManager.cpp ClientManagerHorseName.cpp ClientManagerOfflineshop.cpp version.cpp \
|
||||
AuctionManager.cpp ProtoReader.cpp CsvReader.cpp Ava2ItemShop.cpp Economy.cpp
|
||||
AuctionManager.cpp ProtoReader.cpp CsvReader.cpp Ava2ItemShop.cpp Economy.cpp Cube.cpp CubeRuntime.cpp CubeGold.cpp
|
||||
|
||||
OBJS = $(SRCS:%.cpp=$(OBJDIR)/%.o)
|
||||
|
||||
@@ -47,11 +48,10 @@ default: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJS)
|
||||
@echo linking $(TARGET)....
|
||||
@$(CC) $(CFLAGS) $(LIBDIR) $(OBJS) $(LIBS) -o $(TARGET)
|
||||
$(CC) $(CFLAGS) $(LIBDIR) $(OBJS) $(LIBS) -o $(TARGET)
|
||||
@touch version.cpp
|
||||
@echo "Moving $(TARGET) to $(DBDIR)"
|
||||
@mv $(TARGET) $(DBDIR)
|
||||
@echo "All done! Your db file moved to your server directory."
|
||||
@if [ -d "$(DBDIR)" ]; then cp $(TARGET) $(DBDIR)/; echo "Copied $(TARGET) to $(DBDIR)"; fi
|
||||
@echo "All done!"
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
@echo compile $<
|
||||
@@ -72,3 +72,23 @@ dep:
|
||||
makedepend -fDepend $(INCDIR) -I/usr/include/c++/3.3 -I/usr/include/c++/4.2 -p$(OBJDIR)/ $(SRCS) 2> /dev/null
|
||||
|
||||
sinclude Depend
|
||||
|
||||
# PORT: handwritten economy headers are not present in the legacy Depend file.
|
||||
$(OBJDIR)/Economy.o: ../../common/economy.h ../../common/economy_store.h ../../common/economy_mysql.h ../../common/economy_view.h
|
||||
|
||||
# ClientManager layout and DB result ownership affect every DB translation unit.
|
||||
$(OBJS): ClientManager.h DBManager.h SQLFences.h CubeRuntime.h ../../common/sql_fence_router.h ../../common/cube_batch.h ../../common/cube_recipe.h ../../common/cube_drain.h
|
||||
$(OBJDIR)/CubeRuntime.o: ../../common/cube_fence.h ../../common/cube_store.h ../../common/economy_mysql.h
|
||||
$(OBJS): ../../common/cube_handshake.h
|
||||
$(OBJS): ../../common/cube_mutation.h
|
||||
$(OBJDIR)/CubeGold.o: ../../common/cube_gold_store.h ../../common/cube_gold_intent.h ../../common/cube_store.h ../../common/economy_mysql.h
|
||||
$(OBJDIR)/CubeRuntime.o: ../../common/cube_gold_intent.h
|
||||
$(OBJDIR)/CubeRuntime.o: ../../common/cube_gold_store.h
|
||||
$(OBJS): ../../common/cube_gold_source.h
|
||||
$(OBJS): ../../common/cube_owner_types.h
|
||||
$(OBJDIR)/CubeRuntime.o: ../../common/cube_owner.h
|
||||
$(OBJDIR)/CubeRuntime.o: ../../common/cube_image_ack.h
|
||||
$(OBJDIR)/CubeRuntime.o: ../../common/cube_release.h
|
||||
$(OBJS): ../../common/cube_image.h
|
||||
$(OBJS): ../../common/cube_receipt.h
|
||||
$(OBJDIR)/CubeRuntime.o: ../../common/cube_random.h
|
||||
|
||||
@@ -102,7 +102,7 @@ int get_Item_Type_Value(string inputString)
|
||||
int get_Item_SubType_Value(int type_value, string inputString)
|
||||
{
|
||||
static string arSub1[] = { "WEAPON_SWORD", "WEAPON_DAGGER", "WEAPON_BOW", "WEAPON_TWO_HANDED",
|
||||
"WEAPON_BELL", "WEAPON_FAN", "WEAPON_ARROW", "WEAPON_MOUNT_SPEAR"};
|
||||
"WEAPON_BELL", "WEAPON_FAN", "WEAPON_ARROW", "WEAPON_MOUNT_SPEAR", "WEAPON_CLAW", "WEAPON_QUIVER"};
|
||||
static string arSub2[] = { "ARMOR_BODY", "ARMOR_HEAD", "ARMOR_SHIELD", "ARMOR_WRIST", "ARMOR_FOOTS",
|
||||
"ARMOR_NECK", "ARMOR_EAR", "ARMOR_PENDANT", "ARMOR_NUM_TYPES"};
|
||||
static string arSub3[] = { "USE_POTION", "USE_TALISMAN", "USE_TUNING", "USE_MOVE", "USE_TREASURE_BOX", "USE_MONEYBAG", "USE_BAIT",
|
||||
@@ -251,7 +251,7 @@ int get_Item_AntiFlag_Value(string inputString)
|
||||
|
||||
string arAntiFlag[] = {"ANTI_FEMALE", "ANTI_MALE", "ANTI_MUSA", "ANTI_ASSASSIN", "ANTI_SURA", "ANTI_MUDANG",
|
||||
"ANTI_GET", "ANTI_DROP", "ANTI_SELL", "ANTI_EMPIRE_A", "ANTI_EMPIRE_B", "ANTI_EMPIRE_C",
|
||||
"ANTI_SAVE", "ANTI_GIVE", "ANTI_PKDROP", "ANTI_STACK", "ANTI_MYSHOP", "ANTI_SAFEBOX"};
|
||||
"ANTI_SAVE", "ANTI_GIVE", "ANTI_PKDROP", "ANTI_STACK", "ANTI_MYSHOP", "ANTI_SAFEBOX", "ANTI_WOLFMAN"};
|
||||
|
||||
|
||||
int retValue = 0;
|
||||
@@ -402,13 +402,13 @@ int get_Item_ApplyType_Value(string inputString)
|
||||
"APPLY_EXTRACT_HP_PCT", "APPLY_RESIST_WARRIOR", "APPLY_RESIST_ASSASSIN", "APPLY_RESIST_SURA", "APPLY_RESIST_SHAMAN",
|
||||
"APPLY_ENERGY", "APPLY_DEF_GRADE", "APPLY_COSTUME_ATTR_BONUS", "APPLY_MAGIC_ATTBONUS_PER", "APPLY_MELEE_MAGIC_ATTBONUS_PER",
|
||||
"APPLY_RESIST_ICE", "APPLY_RESIST_EARTH", "APPLY_RESIST_DARK", "APPLY_ANTI_CRITICAL_PCT", "APPLY_ANTI_PENETRATE_PCT",
|
||||
// PORT AVA2 numbering: 92-138 not ported yet (common/length.h)
|
||||
"APPLY_RESERVED_92", "APPLY_RESERVED_93", "APPLY_RESERVED_94", "APPLY_RESERVED_95", "APPLY_RESERVED_96", "APPLY_RESERVED_97", "APPLY_RESIST_MAGIC_REDUCTION", "APPLY_RESIST_HUMAN",
|
||||
// PORT AVA2 numbering: 92-96/138 = Wolfman, the rest not ported yet (common/length.h)
|
||||
"APPLY_BLEEDING_REDUCE", "APPLY_BLEEDING_PCT", "APPLY_ATTBONUS_WOLFMAN", "APPLY_RESIST_WOLFMAN", "APPLY_RESIST_CLAW", "APPLY_RESERVED_97", "APPLY_RESIST_MAGIC_REDUCTION", "APPLY_RESIST_HUMAN",
|
||||
"APPLY_RESERVED_100", "APPLY_RESERVED_101", "APPLY_RESERVED_102", "APPLY_RESERVED_103", "APPLY_RESERVED_104", "APPLY_RESERVED_105", "APPLY_RESERVED_106", "APPLY_RESERVED_107",
|
||||
"APPLY_RESERVED_108", "APPLY_RESERVED_109", "APPLY_RESERVED_110", "APPLY_RESERVED_111", "APPLY_RESERVED_112", "APPLY_RESERVED_113", "APPLY_RESERVED_114", "APPLY_RESERVED_115",
|
||||
"APPLY_RESERVED_116", "APPLY_RESERVED_117", "APPLY_RESERVED_118", "APPLY_RESERVED_119", "APPLY_RESERVED_120", "APPLY_RESERVED_121", "APPLY_RESERVED_122", "APPLY_ENCHANT_ELECT",
|
||||
"APPLY_ENCHANT_FIRE", "APPLY_ENCHANT_ICE", "APPLY_ENCHANT_WIND", "APPLY_ENCHANT_EARTH", "APPLY_ENCHANT_DARK", "APPLY_RESERVED_129", "APPLY_RESERVED_130", "APPLY_RESERVED_131",
|
||||
"APPLY_RESERVED_132", "APPLY_RESERVED_133", "APPLY_RESERVED_134", "APPLY_RESERVED_135", "APPLY_RESERVED_136", "APPLY_RESERVED_137", "APPLY_RESERVED_138",
|
||||
"APPLY_RESERVED_132", "APPLY_RESERVED_133", "APPLY_RESERVED_134", "APPLY_RESERVED_135", "APPLY_RESERVED_136", "APPLY_RESERVED_137", "APPLY_ATTBONUS_CLAW",
|
||||
"APPLY_ATTBONUS_STONE", "APPLY_ATTBONUS_BOSS",
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include "../../common/sql_fence_router.h"
|
||||
|
||||
// Include after libsql/AsyncSQL.h. Every return-query on the PLAYER async queue
|
||||
// must register here; regular fire-and-forget AsyncQuery has no result message.
|
||||
namespace PortSQLFence {
|
||||
// Process-lifetime registry avoids static-destruction order against the DB
|
||||
// singleton. CDBManager::Clear drains ownership explicitly after SQL shutdown.
|
||||
inline Router<SQLMsg>& PlayerRouter(){static auto* router=new Router<SQLMsg>;return *router;}
|
||||
inline bool Queue(CAsyncSQL* sql,Kind kind,uint32_t logical) {
|
||||
if(!sql)return false;const auto ticket=PlayerRouter().Reserve(kind,logical);if(!ticket)return false;
|
||||
sql->ReturnQuery("SELECT 1",reinterpret_cast<void*>(uintptr_t(ticket)));return true;
|
||||
}
|
||||
inline SQLMsg* Pop(CAsyncSQL* sql,Kind kind) {
|
||||
if(sql){SQLMsg* message=nullptr;unsigned budget=1024;while(budget--&&sql->PopResult(&message))PlayerRouter().Complete(message);}
|
||||
return PlayerRouter().Pop(kind);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
#define __INC_METiN_II_DBSERV_STDAFX_H__
|
||||
|
||||
#include "../../libthecore/include/stdafx.h"
|
||||
#include <memory>
|
||||
|
||||
#ifndef __WIN32__
|
||||
#include <semaphore.h>
|
||||
|
||||
@@ -48,6 +48,9 @@ struct FSkillBreath
|
||||
case JOB_SURA: ptr = "sura"; break;
|
||||
case JOB_SHAMAN: ptr = "muda"; break;
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case JOB_WOLFMAN: ptr = "wolf"; break; // TODO: 블루드래곤 수인족 전투 처리
|
||||
#endif
|
||||
default:
|
||||
case JOB_MAX_NUM: return;
|
||||
}
|
||||
@@ -71,6 +74,9 @@ struct FSkillBreath
|
||||
case JOB_SURA: ptr = "sura"; break;
|
||||
case JOB_SHAMAN: ptr = "muda"; break;
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case JOB_WOLFMAN: ptr = "wolf"; break; // TODO: 블루드래곤 수인족 전투 처리
|
||||
#endif
|
||||
default:
|
||||
case JOB_MAX_NUM: return;
|
||||
}
|
||||
@@ -225,6 +231,9 @@ struct FSkillEarthQuake
|
||||
case JOB_ASSASSIN: ptr = "assa"; break;
|
||||
case JOB_SURA: ptr = "sura"; break;
|
||||
case JOB_SHAMAN: ptr = "muda"; break;
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case JOB_WOLFMAN: ptr = "wolf"; break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
case JOB_MAX_NUM: return;
|
||||
@@ -243,6 +252,9 @@ struct FSkillEarthQuake
|
||||
case JOB_ASSASSIN: ptr = "assa"; break;
|
||||
case JOB_SURA: ptr = "sura"; break;
|
||||
case JOB_SHAMAN: ptr = "muda"; break;
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case JOB_WOLFMAN: ptr = "wolf"; break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
case JOB_MAX_NUM: return;
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
#include "ClientPackageCryptInfo.h"
|
||||
#include "../../common/stl.h"
|
||||
|
||||
#ifndef __FreeBSD__
|
||||
#if defined(_WIN32)
|
||||
#include "../../libthecore/include/xdirent.h"
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
CClientPackageCryptInfo::CClientPackageCryptInfo() : m_pSerializedCryptKeyStream(NULL), m_nCryptKeyPackageCnt(0)
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#define INVALID_KERNEL_EVENT -1
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
|
||||
FileMonitorFreeBSD::FileMonitorFreeBSD()
|
||||
{
|
||||
m_KernelEventQueue = INVALID_KERNEL_EVENT;
|
||||
@@ -133,4 +135,12 @@ void FileMonitorFreeBSD::AddWatch(const std::string& strFileName, PFN_FileChange
|
||||
|
||||
m_TriggeredEventLists.push_back( kTriggerEvent );
|
||||
m_MonitoredEventLists.push_back( kMonitorEvent );
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
FileMonitorFreeBSD::FileMonitorFreeBSD() : m_KernelEventQueue(-1) {}
|
||||
FileMonitorFreeBSD::~FileMonitorFreeBSD() {}
|
||||
void FileMonitorFreeBSD::AddWatch(const std::string&, PFN_FileChangeListener) {}
|
||||
void FileMonitorFreeBSD::Update(DWORD) {}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
|
||||
#include "IFileMonitor.h"
|
||||
#include <unistd.h>
|
||||
#ifdef __FreeBSD__
|
||||
#include <sys/event.h>
|
||||
#else
|
||||
struct kevent { int dummy; };
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <sys/signal.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
PLATFORM = $(shell file /bin/ls | cut -d' ' -f3 | cut -d'-' -f1)
|
||||
UNAME_S := $(shell uname -s)
|
||||
UNAME_M := $(shell uname -m)
|
||||
|
||||
GCC_VERSION = $(shell $(CC) --version 2>&1 | grep "(GCC)" | cut -d' ' -f3 | cut -d'.' -f1)
|
||||
BSD_VERSION = $(shell uname -v 2>&1 | cut -d' ' -f2 | cut -d'.' -f1)
|
||||
SVN_VERSION = 40250
|
||||
|
||||
CC = clang++-devel
|
||||
CC ?= clang++-devel
|
||||
|
||||
INCDIR =
|
||||
LIBDIR =
|
||||
BINDIR = ..
|
||||
OBJDIR = OBJDIR
|
||||
GAMEDIR = /usr/metin2/server/share/bin
|
||||
GAMEDIR ?= ../../share/bin
|
||||
SVN_VERSION = 40250
|
||||
$(shell if [ ! -d $(OBJDIR) ]; then mkdir $(OBJDIR); fi)
|
||||
|
||||
# Standard Setting
|
||||
LIBS = -pthread -lm -lmd
|
||||
# Removed -fno-rtti
|
||||
CFLAGS = -g -Wall -w -O2 -m32 -pipe -std=c++2b -fexceptions -D_THREAD_SAFE -DNDEBUG # -D_USE_SERVER_KEY_
|
||||
CFLAGS += -mtune=i686 -fstack-protector-all
|
||||
|
||||
# CryptoPP
|
||||
LIBS += ../../../extern/lib/libcryptopp.a
|
||||
|
||||
# DevIL
|
||||
LIBS += ../../../extern/lib/libIL.a
|
||||
|
||||
# MySQL
|
||||
LIBS += /usr/local/lib/mysql/libmysqlclient.a /usr/lib/libz.a
|
||||
|
||||
# OpenSSL
|
||||
LIBS += /usr/lib/libssl.a /usr/lib/libcrypto.a
|
||||
ifeq ($(UNAME_S), Linux)
|
||||
ifeq ($(UNAME_M), x86_64)
|
||||
ARCH_FLAGS = -m32 -mtune=i686
|
||||
else ifeq ($(UNAME_M), i386)
|
||||
ARCH_FLAGS = -mtune=i686
|
||||
else
|
||||
ARCH_FLAGS =
|
||||
endif
|
||||
CFLAGS ?= -g -Wall -w -O2 $(ARCH_FLAGS) -pipe -std=c++2b -fexceptions -D_THREAD_SAFE -DNDEBUG -fstack-protector-all -fsigned-char
|
||||
INCDIR += -I/usr/include/mariadb -I/usr/include/mysql
|
||||
LIBS = -pthread -lm -lcryptopp -lIL -lILU -lmariadb -lz -lssl -lcrypto -ldl
|
||||
else
|
||||
CFLAGS ?= -g -Wall -w -O2 -m32 -pipe -std=c++2b -fexceptions -D_THREAD_SAFE -DNDEBUG -mtune=i686 -fstack-protector-all
|
||||
LIBS = -pthread -lm -lmd
|
||||
LIBS += ../../../extern/lib/libcryptopp.a
|
||||
LIBS += ../../../extern/lib/libIL.a
|
||||
LIBS += /usr/local/lib/mysql/libmysqlclient.a /usr/lib/libz.a
|
||||
LIBS += /usr/lib/libssl.a /usr/lib/libcrypto.a
|
||||
endif
|
||||
|
||||
# Miscellaneous external libraries
|
||||
INCDIR += -I../../../extern/include
|
||||
@@ -53,7 +53,7 @@ TARGET = $(BINDIR)/game
|
||||
|
||||
CFILE = minilzo.c
|
||||
|
||||
CPPFILE = BattleArena.cpp FSM.cpp MarkConvert.cpp MarkImage.cpp MarkManager.cpp OXEvent.cpp TrafficProfiler.cpp ani.cpp\
|
||||
CPPFILE = port_cube_actor.cpp port_cube_recovery.cpp port_cube_factory.cpp port_cube_apply.cpp port_cube_publish.cpp port_cube_restore.cpp BattleArena.cpp FSM.cpp MarkConvert.cpp MarkImage.cpp MarkManager.cpp OXEvent.cpp TrafficProfiler.cpp ani.cpp\
|
||||
arena.cpp banword.cpp battle.cpp blend_item.cpp block_country.cpp buffer_manager.cpp building.cpp castle.cpp\
|
||||
char.cpp char_affect.cpp char_battle.cpp char_change_empire.cpp char_horse.cpp char_item.cpp char_manager.cpp\
|
||||
char_quickslot.cpp char_resist.cpp char_skill.cpp char_state.cpp PetSystem.cpp cmd.cpp cmd_emotion.cpp cmd_general.cpp\
|
||||
@@ -61,7 +61,7 @@ CPPFILE = BattleArena.cpp FSM.cpp MarkConvert.cpp MarkImage.cpp MarkManager.cpp
|
||||
desc_client.cpp desc_manager.cpp desc_p2p.cpp dev_log.cpp dungeon.cpp empire_text_convert.cpp entity.cpp\
|
||||
entity_view.cpp event.cpp event_queue.cpp exchange.cpp file_loader.cpp fishing.cpp gm.cpp guild.cpp\
|
||||
guild_manager.cpp guild_war.cpp horse_rider.cpp horsename_manager.cpp input.cpp input_auth.cpp input_db.cpp\
|
||||
input_login.cpp input_main.cpp input_p2p.cpp port_boss_track.cpp ava2_channel.cpp new_mob_timer.cpp ava2_track.cpp ava2_ticket_shop.cpp ava2_itemshop.cpp port_attr_lock.cpp port_sash.cpp port_mount.cpp port_costume_attr.cpp port_pendant.cpp port_rings.cpp port_switchbot.cpp port_special_storage.cpp offline_shop.cpp offlineshop_manager.cpp offlineshop_search_manager.cpp port_offlineshop.cpp port_ava2_dungeon.cpp port_gaya.cpp port_economy.cpp input_teen.cpp input_udp.cpp ip_ban.cpp\
|
||||
input_login.cpp input_main.cpp input_p2p.cpp port_boss_track.cpp ava2_channel.cpp new_mob_timer.cpp ava2_track.cpp ava2_ticket_shop.cpp ava2_itemshop.cpp port_attr_lock.cpp port_sash.cpp port_mount.cpp port_costume_attr.cpp port_pendant.cpp port_rings.cpp port_switchbot.cpp port_special_storage.cpp offline_shop.cpp offlineshop_manager.cpp offlineshop_search_manager.cpp port_offlineshop.cpp port_ava2_dungeon.cpp port_gaya.cpp port_cheque.cpp port_economy.cpp input_teen.cpp input_udp.cpp ip_ban.cpp\
|
||||
item.cpp item_addon.cpp item_attribute.cpp item_manager.cpp item_manager_idrange.cpp locale.cpp\
|
||||
locale_service.cpp log.cpp login_data.cpp lzo_manager.cpp marriage.cpp matrix_card.cpp\
|
||||
messenger_manager.cpp mining.cpp mob_manager.cpp monarch.cpp motion.cpp over9refine.cpp p2p.cpp packet_info.cpp\
|
||||
@@ -108,10 +108,9 @@ limit_time:
|
||||
|
||||
$(TARGET): $(CPPOBJS) $(COBJS) $(MAINOBJ)
|
||||
@echo linking $(TARGET)....
|
||||
@$(CC) $(CFLAGS) $(LIBDIR) $(COBJS) $(CPPOBJS) $(MAINOBJ) $(LIBS) -o $(TARGET)
|
||||
@echo "Moving $(TARGET) to $(GAMEDIR)"
|
||||
@mv $(TARGET) $(GAMEDIR)
|
||||
@echo "All done! Your game file moved to your server directory."
|
||||
$(CC) $(CFLAGS) $(LIBDIR) $(COBJS) $(CPPOBJS) $(MAINOBJ) $(LIBS) -o $(TARGET)
|
||||
@if [ -d "$(GAMEDIR)" ]; then cp $(TARGET) $(GAMEDIR)/; echo "Copied $(TARGET) to $(GAMEDIR)"; fi
|
||||
@echo "All done!"
|
||||
|
||||
clean:
|
||||
@rm -f $(COBJS) $(CPPOBJS) $(MAINOBJ)
|
||||
@@ -146,3 +145,35 @@ $(OBJDIR)/char.o $(OBJDIR)/cmd_general.o $(OBJDIR)/input_p2p.o $(OBJDIR)/p2p.o $
|
||||
|
||||
$(OBJDIR)/cmd_general.o: port_features.h port_rank_runtime.h
|
||||
$(OBJDIR)/char_battle.o $(OBJDIR)/char_skill.o: port_magic_reduction.h
|
||||
$(OBJDIR)/char_battle.o: port_quiver.h
|
||||
$(OBJDIR)/char.o: port_quiver.h port_quiver_sync.inc
|
||||
$(OBJDIR)/cube.o: port_cube_catalog.inc ../../common/cube_recipe.h cube.h
|
||||
$(OBJDIR)/port_cube_actor.o $(OBJDIR)/input_db.o: port_cube_actor.h ../../common/cube_handshake.h ../../common/cube_batch.h
|
||||
$(OBJDIR)/char.o $(OBJDIR)/char_item.o $(OBJDIR)/main.o: port_cube_actor.h
|
||||
$(OBJDIR)/item_manager.o: port_cube_flush.inc item_manager.h
|
||||
$(OBJDIR)/cube.o: ../../common/cube_batch.h
|
||||
$(OBJDIR)/port_cube_actor.o $(OBJDIR)/char.o $(OBJDIR)/item.o: ../../common/cube_mutation.h
|
||||
$(OBJDIR)/item.o: port_cube_item.inc port_cube_actor.h
|
||||
$(OBJDIR)/questpc.o $(OBJDIR)/questmanager.o: port_cube_quest.h questpc.h
|
||||
$(OBJDIR)/port_cube_actor.o: questpc.h port_switchbot.h item.h
|
||||
$(OBJDIR)/port_cube_actor.o: ../../common/cube_gold_outbox.h ../../common/cube_gold_intent.h ../../common/cube_store.h
|
||||
$(OBJDIR)/port_cube_actor.o $(OBJDIR)/input_db.o: ../../common/cube_gold_source.h
|
||||
$(OBJDIR)/port_switchbot.o $(OBJDIR)/cube.o: port_cube_actor.h
|
||||
$(CPPOBJS) $(MAINOBJ): char.h item.h questpc.h questmanager.h
|
||||
$(OBJDIR)/port_cube_recovery.o $(OBJDIR)/input_db.o $(OBJDIR)/input_login.o $(OBJDIR)/main.o: port_cube_recovery.h ../../common/cube_recovery.h ../../common/cube_owner_types.h
|
||||
$(OBJDIR)/port_cube_actor.o: ../../common/cube_owner_types.h
|
||||
$(OBJDIR)/port_cube_actor.o $(OBJDIR)/port_cube_recovery.o $(OBJDIR)/input_db.o: ../../common/cube_image.h
|
||||
$(OBJDIR)/port_cube_actor.o: ../../common/cube_craft.h ../../common/cube_receipt.h
|
||||
$(OBJDIR)/item_manager_idrange.o: port_cube_ids.h ../../common/cube_item_ids.h
|
||||
$(OBJDIR)/port_cube_factory.o $(OBJDIR)/item_manager.o: port_cube_factory.h
|
||||
$(OBJDIR)/port_cube_actor.o: port_cube_factory.h
|
||||
$(OBJDIR)/port_cube_actor.o: ../../common/cube_live_image.h
|
||||
$(OBJDIR)/port_cube_recovery.o: ../../common/cube_handshake.h
|
||||
$(OBJDIR)/port_cube_actor.o $(OBJDIR)/port_cube_publish.o $(OBJDIR)/item.o: ../../common/cube_presentation.h
|
||||
$(OBJDIR)/port_cube_actor.o $(OBJDIR)/port_cube_publish.o: port_cube_publish.h
|
||||
$(OBJDIR)/port_cube_actor.o $(OBJDIR)/port_cube_restore.o: port_cube_restore.h
|
||||
$(OBJDIR)/item.o: port_cube_lifecycle.inc event_queue.h event.h
|
||||
$(OBJDIR)/port_cube_apply.o $(OBJDIR)/port_cube_actor.o: port_cube_apply.h
|
||||
$(OBJDIR)/item_manager.o: port_cube_registry.inc
|
||||
$(OBJDIR)/port_cube_factory.o: port_cube_ids.h ../../common/economy.h
|
||||
$(OBJDIR)/port_cube_recovery.o $(OBJDIR)/input_db.o: ../../common/cube_receipt.h
|
||||
|
||||
@@ -424,7 +424,7 @@ bool COXEventManager::LogWinner()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool COXEventManager::GiveItemToAttender(DWORD dwItemVnum, BYTE count)
|
||||
bool COXEventManager::GiveItemToAttender(DWORD dwItemVnum, DWORD count)
|
||||
{
|
||||
itertype(m_map_attender) iter = m_map_attender.begin();
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ class COXEventManager : public singleton<COXEventManager>
|
||||
bool ShowQuizList(LPCHARACTER pChar);
|
||||
|
||||
bool Quiz(unsigned char level, int timelimit);
|
||||
bool GiveItemToAttender(DWORD dwItemVnum, BYTE count);
|
||||
bool GiveItemToAttender(DWORD dwItemVnum, DWORD count);
|
||||
|
||||
bool CheckAnswer(bool answer);
|
||||
void WarpToAudience();
|
||||
|
||||
@@ -56,6 +56,9 @@ enum EAffectTypes
|
||||
|
||||
AFFECT_BOW_DISTANCE, // 225
|
||||
AFFECT_DEF_GRADE, // 226
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
AFFECT_BLEEDING, // 227
|
||||
#endif
|
||||
|
||||
AFFECT_PREMIUM_START = 500,
|
||||
AFFECT_EXP_BONUS = 500, // 경험의 반지
|
||||
@@ -110,6 +113,13 @@ enum EAffectTypes
|
||||
AFFECT_NOG_ABILITY = 302,
|
||||
AFFECT_HOLLY_STONE_POWER = 303,
|
||||
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
AFFECT_SUNGMA_STR = 907,
|
||||
AFFECT_SUNGMA_HP = 908,
|
||||
AFFECT_SUNGMA_MOVE = 909,
|
||||
AFFECT_SUNGMA_INMUNE = 910,
|
||||
#endif
|
||||
|
||||
AFFECT_QUEST_START_IDX = 1000
|
||||
};
|
||||
|
||||
@@ -165,6 +175,16 @@ enum EAffectBits
|
||||
AFF_CHINA_FIREWORK,
|
||||
AFF_HAIR, // 헤어
|
||||
AFF_GERMANY, // 독일
|
||||
AFF_RAMADAN_RING, // 42 (client AFFECT_RAMADAN_RING 41)
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
AFF_BLEEDING, // 43
|
||||
AFF_RED_POSSESSION, // 44
|
||||
AFF_BLUE_POSSESSION, // 45
|
||||
#endif
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
AFF_CHEONUN = 46, // skill_proto setAffectFlag enum index 46
|
||||
AFF_CHUNWOON_MOOJUK = 47,
|
||||
#endif
|
||||
|
||||
AFF_BITS_MAX
|
||||
};
|
||||
|
||||
@@ -26,6 +26,9 @@ const char* FN_race_name(int race)
|
||||
FN_NAME(MAIN_RACE_ASSASSIN_M);
|
||||
FN_NAME(MAIN_RACE_SURA_W);
|
||||
FN_NAME(MAIN_RACE_SHAMAN_M);
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
FN_NAME(MAIN_RACE_WOLFMAN_M);
|
||||
#endif
|
||||
FN_NAME(MAIN_RACE_MAX_NUM);
|
||||
}
|
||||
|
||||
@@ -46,6 +49,9 @@ const char* FN_weapon_type(int weapon)
|
||||
FN_NAME(WEAPON_FAN);
|
||||
FN_NAME(WEAPON_ARROW);
|
||||
FN_NAME(WEAPON_MOUNT_SPEAR);
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
FN_NAME(WEAPON_CLAW);
|
||||
#endif
|
||||
FN_NAME(WEAPON_NUM_TYPES);
|
||||
}
|
||||
|
||||
@@ -134,7 +140,10 @@ bool ANI::load()
|
||||
"data/pc2/warrior", // ¹«»ç(¿©)
|
||||
"data/pc2/assassin", // ÀÚ°´(³²)
|
||||
"data/pc2/sura", // ¼ö¶ó(¿©)
|
||||
"data/pc2/shaman" // 公寸(巢)
|
||||
"data/pc2/shaman", // ¹«´ç(³²)
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
"data/pc3/wolfman", // ¼öÀÎÁ·
|
||||
#endif
|
||||
};
|
||||
|
||||
for (int race = 0; race <MAIN_RACE_MAX_NUM; ++race)
|
||||
@@ -180,6 +189,11 @@ DWORD ANI::load_one_weapon(const char *dir_name, int weapon, BYTE combo, bool ho
|
||||
strlcpy(format, "%s/%sfan/combo_%02d.msa", sizeof(format));
|
||||
break;
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case WEAPON_CLAW:
|
||||
strlcpy(format, "%s/%sclaw/combo_%02d.msa", sizeof(format));
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return 1000;
|
||||
}
|
||||
@@ -234,6 +248,9 @@ DWORD ANI::attack_speed(int race, int weapon, BYTE combo, bool horse)
|
||||
case MAIN_RACE_ASSASSIN_M:
|
||||
case MAIN_RACE_SURA_W:
|
||||
case MAIN_RACE_SHAMAN_M:
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case MAIN_RACE_WOLFMAN_M:
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
return 1000;
|
||||
@@ -249,6 +266,9 @@ DWORD ANI::attack_speed(int race, int weapon, BYTE combo, bool horse)
|
||||
case WEAPON_FAN:
|
||||
case WEAPON_ARROW:
|
||||
case WEAPON_MOUNT_SPEAR:
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case WEAPON_CLAW:
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
return 1000;
|
||||
@@ -270,6 +290,9 @@ const char* FN_race_string(int race)
|
||||
case MAIN_RACE_ASSASSIN_M: return "ASSASSIN_M";
|
||||
case MAIN_RACE_SURA_W: return "SURA_W";
|
||||
case MAIN_RACE_SHAMAN_M: return "SHAMAN_M";
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case MAIN_RACE_WOLFMAN_M: return "WOLFMAN_M";
|
||||
#endif
|
||||
}
|
||||
|
||||
return "UNKNOWN_RACE";
|
||||
@@ -287,6 +310,9 @@ const char* FN_weapon_string(int weapon)
|
||||
case WEAPON_FAN: return "FAN";
|
||||
case WEAPON_ARROW: return "ARROW";
|
||||
case WEAPON_MOUNT_SPEAR:return "WEAPON_MOUNT_SPEAR";
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case WEAPON_CLAW: return "CLAW";
|
||||
#endif
|
||||
}
|
||||
|
||||
return "UNKNOWN";
|
||||
|
||||
@@ -80,7 +80,7 @@ bool CArenaMap::AddArena(DWORD mapIdx, WORD startA_X, WORD startA_Y, WORD startB
|
||||
|
||||
for (; iter != m_listArena.end(); iter++)
|
||||
{
|
||||
if ((CArena*)(*iter)->CheckArea(startA_X, startA_Y, startB_X, startB_Y) == false)
|
||||
if ((*iter)->CheckArea(startA_X, startA_Y, startB_X, startB_Y) == false)
|
||||
{
|
||||
sys_log(0, "CArenaMap::AddArena - Same Start Position set. stA(%d, %d) stB(%d, %d)", startA_X, startA_Y, startB_X, startB_Y);
|
||||
return false;
|
||||
@@ -237,17 +237,17 @@ EVENTFUNC(ready_to_start_event)
|
||||
|
||||
if (chA != NULL)
|
||||
{
|
||||
chA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련 상대가 사라져 대련을 종료합니다."));
|
||||
chA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련 상대가 사라져 대련을 종료합니다."));
|
||||
sys_log(0, "ARENA: Oppernent is disappered. MyPID(%d) OppPID(%d)", pArena->GetPlayerAPID(), pArena->GetPlayerBPID());
|
||||
}
|
||||
|
||||
if (chB != NULL)
|
||||
{
|
||||
chB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련 상대가 사라져 대련을 종료합니다."));
|
||||
chB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련 상대가 사라져 대련을 종료합니다."));
|
||||
sys_log(0, "ARENA: Oppernent is disappered. MyPID(%d) OppPID(%d)", pArena->GetPlayerBPID(), pArena->GetPlayerAPID());
|
||||
}
|
||||
|
||||
pArena->SendChatPacketToObserver(CHAT_TYPE_NOTICE, LC_TEXT("대련 상대가 사라져 대련을 종료합니다."));
|
||||
pArena->SendChatPacketToObserver(CHAT_TYPE_NOTICE, LC_TEXT("대련 상대가 사라져 대련을 종료합니다."));
|
||||
|
||||
pArena->EndDuel();
|
||||
return 0;
|
||||
@@ -264,20 +264,20 @@ EVENTFUNC(ready_to_start_event)
|
||||
|
||||
if (count > 10000)
|
||||
{
|
||||
chA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("물약 제한이 없습니다."));
|
||||
chB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("물약 제한이 없습니다."));
|
||||
chA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("물약 제한이 없습니다."));
|
||||
chB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("물약 제한이 없습니다."));
|
||||
}
|
||||
else
|
||||
{
|
||||
chA->SetPotionLimit(count);
|
||||
chB->SetPotionLimit(count);
|
||||
|
||||
chA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("물약을 %d 개 까지 사용 가능합니다."), chA->GetPotionLimit());
|
||||
chB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("물약을 %d 개 까지 사용 가능합니다."), chB->GetPotionLimit());
|
||||
chA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("물약을 %d 개 까지 사용 가능합니다."), chA->GetPotionLimit());
|
||||
chB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("물약을 %d 개 까지 사용 가능합니다."), chB->GetPotionLimit());
|
||||
}
|
||||
chA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("10초뒤 대련이 시작됩니다."));
|
||||
chB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("10초뒤 대련이 시작됩니다."));
|
||||
pArena->SendChatPacketToObserver(CHAT_TYPE_INFO, LC_TEXT("10초뒤 대련이 시작됩니다."));
|
||||
chA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("10초뒤 대련이 시작됩니다."));
|
||||
chB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("10초뒤 대련이 시작됩니다."));
|
||||
pArena->SendChatPacketToObserver(CHAT_TYPE_INFO, LC_TEXT("10초뒤 대련이 시작됩니다."));
|
||||
|
||||
info->state++;
|
||||
return PASSES_PER_SEC(10);
|
||||
@@ -286,15 +286,15 @@ EVENTFUNC(ready_to_start_event)
|
||||
|
||||
case 1:
|
||||
{
|
||||
chA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련이 시작되었습니다."));
|
||||
chB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련이 시작되었습니다."));
|
||||
pArena->SendChatPacketToObserver(CHAT_TYPE_INFO, LC_TEXT("대련이 시작되었습니다."));
|
||||
chA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련이 시작되었습니다."));
|
||||
chB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련이 시작되었습니다."));
|
||||
pArena->SendChatPacketToObserver(CHAT_TYPE_INFO, LC_TEXT("대련이 시작되었습니다."));
|
||||
|
||||
TPacketGCDuelStart duelStart;
|
||||
duelStart.header = HEADER_GC_DUEL_START;
|
||||
duelStart.wSize = sizeof(TPacketGCDuelStart) + 4;
|
||||
|
||||
DWORD dwOppList[8]; // 최대 파티원 8명 이므로..
|
||||
DWORD dwOppList[8]; // 최대 파티원 8명 이므로..
|
||||
|
||||
dwOppList[0] = (DWORD)chB->GetVID();
|
||||
TEMP_BUFFER buf;
|
||||
@@ -343,7 +343,7 @@ EVENTFUNC(ready_to_start_event)
|
||||
|
||||
TEMP_BUFFER buf;
|
||||
TEMP_BUFFER buf2;
|
||||
DWORD dwOppList[8]; // 최대 파티원 8명 이므로..
|
||||
DWORD dwOppList[8]; // 최대 파티원 8명 이므로..
|
||||
TPacketGCDuelStart duelStart;
|
||||
duelStart.header = HEADER_GC_DUEL_START;
|
||||
duelStart.wSize = sizeof(TPacketGCDuelStart) + 4;
|
||||
@@ -358,9 +358,9 @@ EVENTFUNC(ready_to_start_event)
|
||||
buf2.write(&dwOppList[0], 4);
|
||||
chB->GetDesc()->Packet(buf2.read_peek(), buf2.size());
|
||||
|
||||
chA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련이 시작되었습니다."));
|
||||
chB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련이 시작되었습니다."));
|
||||
pArena->SendChatPacketToObserver(CHAT_TYPE_INFO, LC_TEXT("대련이 시작되었습니다."));
|
||||
chA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련이 시작되었습니다."));
|
||||
chB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련이 시작되었습니다."));
|
||||
pArena->SendChatPacketToObserver(CHAT_TYPE_INFO, LC_TEXT("대련이 시작되었습니다."));
|
||||
|
||||
pArena->ClearEvent();
|
||||
|
||||
@@ -370,9 +370,9 @@ EVENTFUNC(ready_to_start_event)
|
||||
|
||||
default:
|
||||
{
|
||||
chA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련장 문제로 인하여 대련을 종료합니다."));
|
||||
chB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련장 문제로 인하여 대련을 종료합니다."));
|
||||
pArena->SendChatPacketToObserver(CHAT_TYPE_INFO, LC_TEXT("대련장 문제로 인하여 대련을 종료합니다."));
|
||||
chA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련장 문제로 인하여 대련을 종료합니다."));
|
||||
chB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련장 문제로 인하여 대련을 종료합니다."));
|
||||
pArena->SendChatPacketToObserver(CHAT_TYPE_INFO, LC_TEXT("대련장 문제로 인하여 대련을 종료합니다."));
|
||||
|
||||
sys_log(0, "ARENA: Something wrong in event func. info->state(%d)", info->state);
|
||||
|
||||
@@ -411,17 +411,17 @@ EVENTFUNC(duel_time_out)
|
||||
{
|
||||
if (chA != NULL)
|
||||
{
|
||||
chA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련 상대가 사라져 대련을 종료합니다."));
|
||||
chA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련 상대가 사라져 대련을 종료합니다."));
|
||||
sys_log(0, "ARENA: Oppernent is disappered. MyPID(%d) OppPID(%d)", pArena->GetPlayerAPID(), pArena->GetPlayerBPID());
|
||||
}
|
||||
|
||||
if (chB != NULL)
|
||||
{
|
||||
chB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련 상대가 사라져 대련을 종료합니다."));
|
||||
chB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("대련 상대가 사라져 대련을 종료합니다."));
|
||||
sys_log(0, "ARENA: Oppernent is disappered. MyPID(%d) OppPID(%d)", pArena->GetPlayerBPID(), pArena->GetPlayerAPID());
|
||||
}
|
||||
|
||||
pArena->SendChatPacketToObserver(CHAT_TYPE_INFO, LC_TEXT("대련 상대가 사라져 대련을 종료합니다."));
|
||||
pArena->SendChatPacketToObserver(CHAT_TYPE_INFO, LC_TEXT("대련 상대가 사라져 대련을 종료합니다."));
|
||||
|
||||
pArena->EndDuel();
|
||||
return 0;
|
||||
@@ -431,14 +431,14 @@ EVENTFUNC(duel_time_out)
|
||||
switch (info->state)
|
||||
{
|
||||
case 0:
|
||||
pArena->SendChatPacketToObserver(CHAT_TYPE_NOTICE, LC_TEXT("대련 시간 초과로 대련을 중단합니다."));
|
||||
pArena->SendChatPacketToObserver(CHAT_TYPE_NOTICE, LC_TEXT("10초뒤 마을로 이동합니다."));
|
||||
pArena->SendChatPacketToObserver(CHAT_TYPE_NOTICE, LC_TEXT("대련 시간 초과로 대련을 중단합니다."));
|
||||
pArena->SendChatPacketToObserver(CHAT_TYPE_NOTICE, LC_TEXT("10초뒤 마을로 이동합니다."));
|
||||
|
||||
chA->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("대련 시간 초과로 대련을 중단합니다."));
|
||||
chA->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("10초뒤 마을로 이동합니다."));
|
||||
chA->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("대련 시간 초과로 대련을 중단합니다."));
|
||||
chA->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("10초뒤 마을로 이동합니다."));
|
||||
|
||||
chB->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("대련 시간 초과로 대련을 중단합니다."));
|
||||
chB->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("10초뒤 마을로 이동합니다."));
|
||||
chB->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("대련 시간 초과로 대련을 중단합니다."));
|
||||
chB->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("10초뒤 마을로 이동합니다."));
|
||||
|
||||
TPacketGCDuelStart duelStart;
|
||||
duelStart.header = HEADER_GC_DUEL_START;
|
||||
@@ -682,7 +682,7 @@ bool CArenaMap::CanAttack(LPCHARACTER pCharAttacker, LPCHARACTER pCharVictim)
|
||||
|
||||
bool CArena::CanAttack(DWORD dwPIDA, DWORD dwPIDB)
|
||||
{
|
||||
// 1:1 전용 다대다 할 경우 수정 필요
|
||||
// 1:1 전용 다대다 할 경우 수정 필요
|
||||
if (m_dwPIDA == dwPIDA && m_dwPIDB == dwPIDB) return true;
|
||||
if (m_dwPIDA == dwPIDB && m_dwPIDB == dwPIDA) return true;
|
||||
|
||||
@@ -732,20 +732,20 @@ bool CArena::OnDead(DWORD dwPIDA, DWORD dwPIDB)
|
||||
|
||||
if (pCharA == NULL && pCharB == NULL)
|
||||
{
|
||||
// 둘다 접속이 끊어졌다 ?!
|
||||
SendChatPacketToObserver(CHAT_TYPE_NOTICE, LC_TEXT("대련자 문제로 인하여 대련을 중단합니다."));
|
||||
// 둘다 접속이 끊어졌다 ?!
|
||||
SendChatPacketToObserver(CHAT_TYPE_NOTICE, LC_TEXT("대련자 문제로 인하여 대련을 중단합니다."));
|
||||
restart = false;
|
||||
}
|
||||
else if (pCharA == NULL && pCharB != NULL)
|
||||
{
|
||||
pCharB->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("상대방 캐릭터의 문제로 인하여 대련을 종료합니다."));
|
||||
SendChatPacketToObserver(CHAT_TYPE_NOTICE, LC_TEXT("대련자 문제로 인하여 대련을 종료합니다."));
|
||||
pCharB->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("상대방 캐릭터의 문제로 인하여 대련을 종료합니다."));
|
||||
SendChatPacketToObserver(CHAT_TYPE_NOTICE, LC_TEXT("대련자 문제로 인하여 대련을 종료합니다."));
|
||||
restart = false;
|
||||
}
|
||||
else if (pCharA != NULL && pCharB == NULL)
|
||||
{
|
||||
pCharA->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("상대방 캐릭터의 문제로 인하여 대련을 종료합니다."));
|
||||
SendChatPacketToObserver(CHAT_TYPE_NOTICE, LC_TEXT("대련자 문제로 인하여 대련을 종료합니다."));
|
||||
pCharA->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("상대방 캐릭터의 문제로 인하여 대련을 종료합니다."));
|
||||
SendChatPacketToObserver(CHAT_TYPE_NOTICE, LC_TEXT("대련자 문제로 인하여 대련을 종료합니다."));
|
||||
restart = false;
|
||||
}
|
||||
else if (pCharA != NULL && pCharB != NULL)
|
||||
@@ -756,9 +756,9 @@ bool CArena::OnDead(DWORD dwPIDA, DWORD dwPIDB)
|
||||
|
||||
if (m_dwSetPointOfA >= m_dwSetCount)
|
||||
{
|
||||
pCharA->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("%s 님이 대련에서 승리하였습니다."), pCharA->GetName());
|
||||
pCharB->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("%s 님이 대련에서 승리하였습니다."), pCharA->GetName());
|
||||
SendChatPacketToObserver(CHAT_TYPE_NOTICE, LC_TEXT("%s 님이 대련에서 승리하였습니다."), pCharA->GetName());
|
||||
pCharA->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("%s 님이 대련에서 승리하였습니다."), pCharA->GetName());
|
||||
pCharB->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("%s 님이 대련에서 승리하였습니다."), pCharA->GetName());
|
||||
SendChatPacketToObserver(CHAT_TYPE_NOTICE, LC_TEXT("%s 님이 대련에서 승리하였습니다."), pCharA->GetName());
|
||||
|
||||
sys_log(0, "ARENA: Duel is end. Winner %s(%d) Loser %s(%d)",
|
||||
pCharA->GetName(), GetPlayerAPID(), pCharB->GetName(), GetPlayerBPID());
|
||||
@@ -766,10 +766,10 @@ bool CArena::OnDead(DWORD dwPIDA, DWORD dwPIDB)
|
||||
else
|
||||
{
|
||||
restart = true;
|
||||
pCharA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%s 님이 승리하였습니다."), pCharA->GetName());
|
||||
pCharA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%s 님이 승리하였습니다."), pCharA->GetName());
|
||||
pCharA->ChatPacket(CHAT_TYPE_NOTICE, "%s %d : %d %s", pCharA->GetName(), m_dwSetPointOfA, m_dwSetPointOfB, pCharB->GetName());
|
||||
|
||||
pCharB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%s 님이 승리하였습니다."), pCharA->GetName());
|
||||
pCharB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%s 님이 승리하였습니다."), pCharA->GetName());
|
||||
pCharB->ChatPacket(CHAT_TYPE_NOTICE, "%s %d : %d %s", pCharA->GetName(), m_dwSetPointOfA, m_dwSetPointOfB, pCharB->GetName());
|
||||
|
||||
SendChatPacketToObserver(CHAT_TYPE_NOTICE, "%s %d : %d %s", pCharA->GetName(), m_dwSetPointOfA, m_dwSetPointOfB, pCharB->GetName());
|
||||
@@ -783,19 +783,19 @@ bool CArena::OnDead(DWORD dwPIDA, DWORD dwPIDB)
|
||||
m_dwSetPointOfB++;
|
||||
if (m_dwSetPointOfB >= m_dwSetCount)
|
||||
{
|
||||
pCharA->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("%s 님이 대련에서 승리하였습니다."), pCharB->GetName());
|
||||
pCharB->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("%s 님이 대련에서 승리하였습니다."), pCharB->GetName());
|
||||
SendChatPacketToObserver(CHAT_TYPE_NOTICE, LC_TEXT("%s 님이 대련에서 승리하였습니다."), pCharB->GetName());
|
||||
pCharA->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("%s 님이 대련에서 승리하였습니다."), pCharB->GetName());
|
||||
pCharB->ChatPacket(CHAT_TYPE_NOTICE, LC_TEXT("%s 님이 대련에서 승리하였습니다."), pCharB->GetName());
|
||||
SendChatPacketToObserver(CHAT_TYPE_NOTICE, LC_TEXT("%s 님이 대련에서 승리하였습니다."), pCharB->GetName());
|
||||
|
||||
sys_log(0, "ARENA: Duel is end. Winner(%d) Loser(%d)", GetPlayerBPID(), GetPlayerAPID());
|
||||
}
|
||||
else
|
||||
{
|
||||
restart = true;
|
||||
pCharA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%s 님이 승리하였습니다."), pCharB->GetName());
|
||||
pCharA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%s 님이 승리하였습니다."), pCharB->GetName());
|
||||
pCharA->ChatPacket(CHAT_TYPE_NOTICE, "%s %d : %d %s", pCharA->GetName(), m_dwSetPointOfA, m_dwSetPointOfB, pCharB->GetName());
|
||||
|
||||
pCharB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%s 님이 승리하였습니다."), pCharB->GetName());
|
||||
pCharB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%s 님이 승리하였습니다."), pCharB->GetName());
|
||||
pCharB->ChatPacket(CHAT_TYPE_NOTICE, "%s %d : %d %s", pCharA->GetName(), m_dwSetPointOfA, m_dwSetPointOfB, pCharB->GetName());
|
||||
|
||||
SendChatPacketToObserver(CHAT_TYPE_NOTICE, "%s %d : %d %s", pCharA->GetName(), m_dwSetPointOfA, m_dwSetPointOfB, pCharB->GetName());
|
||||
@@ -815,18 +815,18 @@ bool CArena::OnDead(DWORD dwPIDA, DWORD dwPIDB)
|
||||
}
|
||||
else
|
||||
{
|
||||
// 오면 안된다 ?!
|
||||
// 오면 안된다 ?!
|
||||
}
|
||||
|
||||
if (restart == false)
|
||||
{
|
||||
if (pCharA != NULL)
|
||||
pCharA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("10초뒤 마을로 되돌아갑니다."));
|
||||
pCharA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("10초뒤 마을로 되돌아갑니다."));
|
||||
|
||||
if ( pCharB != NULL)
|
||||
pCharB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("10초뒤 마을로 되돌아갑니다."));
|
||||
pCharB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("10초뒤 마을로 되돌아갑니다."));
|
||||
|
||||
SendChatPacketToObserver(CHAT_TYPE_INFO, LC_TEXT("10초뒤 마을로 되돌아갑니다."));
|
||||
SendChatPacketToObserver(CHAT_TYPE_INFO, LC_TEXT("10초뒤 마을로 되돌아갑니다."));
|
||||
|
||||
if (m_pEvent != NULL) {
|
||||
event_cancel(&m_pEvent);
|
||||
@@ -842,12 +842,12 @@ bool CArena::OnDead(DWORD dwPIDA, DWORD dwPIDB)
|
||||
else
|
||||
{
|
||||
if (pCharA != NULL)
|
||||
pCharA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("10초뒤 다음 판을 시작합니다."));
|
||||
pCharA->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("10초뒤 다음 판을 시작합니다."));
|
||||
|
||||
if (pCharB != NULL)
|
||||
pCharB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("10초뒤 다음 판을 시작합니다."));
|
||||
pCharB->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("10초뒤 다음 판을 시작합니다."));
|
||||
|
||||
SendChatPacketToObserver(CHAT_TYPE_INFO, LC_TEXT("10초뒤 다음 판을 시작합니다."));
|
||||
SendChatPacketToObserver(CHAT_TYPE_INFO, LC_TEXT("10초뒤 다음 판을 시작합니다."));
|
||||
|
||||
if (m_pEvent != NULL) {
|
||||
event_cancel(&m_pEvent);
|
||||
@@ -953,7 +953,7 @@ void CArena::OnDisconnect(DWORD pid)
|
||||
if (m_dwPIDA == pid)
|
||||
{
|
||||
if (GetPlayerB() != NULL)
|
||||
GetPlayerB()->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상대방 캐릭터가 접속을 종료하여 대련을 중지합니다."));
|
||||
GetPlayerB()->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상대방 캐릭터가 접속을 종료하여 대련을 중지합니다."));
|
||||
|
||||
sys_log(0, "ARENA : Duel is end because of Opp(%d) is disconnect. MyPID(%d)", GetPlayerAPID(), GetPlayerBPID());
|
||||
EndDuel();
|
||||
@@ -961,7 +961,7 @@ void CArena::OnDisconnect(DWORD pid)
|
||||
else if (m_dwPIDB == pid)
|
||||
{
|
||||
if (GetPlayerA() != NULL)
|
||||
GetPlayerA()->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상대방 캐릭터가 접속을 종료하여 대련을 중지합니다."));
|
||||
GetPlayerA()->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상대방 캐릭터가 접속을 종료하여 대련을 중지합니다."));
|
||||
|
||||
sys_log(0, "ARENA : Duel is end because of Opp(%d) is disconnect. MyPID(%d)", GetPlayerBPID(), GetPlayerAPID());
|
||||
EndDuel();
|
||||
|
||||
@@ -52,14 +52,14 @@ bool CHARACTER::AutoGiveItemChest(LPITEM item, DWORD& itemCount, std::map<LPITEM
|
||||
for (auto it = vecUpdateItems.begin(); it != vecUpdateItems.end(); ++it)
|
||||
{
|
||||
LPITEM item2 = it->first;
|
||||
if (itemVnum == item2->GetVnum())
|
||||
if (item2->CanStackWith(item))
|
||||
{
|
||||
bool same=true;
|
||||
for(int j=0;j<ITEM_SOCKET_MAX_NUM;++j)
|
||||
if(item2->GetSocket(j)!=item->GetSocket(j)) same=false;
|
||||
if(!same) continue;
|
||||
const DWORD item2Count = item2->GetCount();
|
||||
const WORD bCount2 = MIN(ITEM_MAX_COUNT - item2Count, wCount);
|
||||
const WORD bCount2 = MIN(item2->GetStackRoom(), wCount);
|
||||
if (bCount2 > 0)
|
||||
{
|
||||
wCount -= bCount2;
|
||||
@@ -78,7 +78,7 @@ bool CHARACTER::AutoGiveItemChest(LPITEM item, DWORD& itemCount, std::map<LPITEM
|
||||
LPITEM item2 = GetInventoryItem(i);
|
||||
if (!item2)
|
||||
continue;
|
||||
if (item2->GetVnum() == itemVnum)
|
||||
if (item2->CanStackWith(item))
|
||||
{
|
||||
BYTE j;
|
||||
for (j = 0; j < ITEM_SOCKET_MAX_NUM; ++j)
|
||||
@@ -87,7 +87,7 @@ bool CHARACTER::AutoGiveItemChest(LPITEM item, DWORD& itemCount, std::map<LPITEM
|
||||
if (j != ITEM_SOCKET_MAX_NUM)
|
||||
continue;
|
||||
const DWORD item2Count = item2->GetCount();
|
||||
const WORD bCount2 = MIN(ITEM_MAX_COUNT - item2Count, wCount);
|
||||
const WORD bCount2 = MIN(item2->GetStackRoom(), wCount);
|
||||
if (bCount2 > 0)
|
||||
{
|
||||
const auto itItem = vecUpdateItems.find(item2);
|
||||
@@ -229,11 +229,15 @@ bool CHARACTER::GiveItemFromSpecialItemGroupNew(DWORD dwGroupNum, WORD& loopCoun
|
||||
break;
|
||||
default:
|
||||
{
|
||||
// The selected base has 200-count stacks and byte item-count packets.
|
||||
// AVA2 rewards larger than a stack must be split, never silently clamped by CreateItem.
|
||||
const auto* proto = ITEM_MANAGER::Instance().GetTable(dwVnum);
|
||||
if (!proto) { --returnCount; break; }
|
||||
unsigned limit = PortMaterialStackPolicy::GrantLimit(proto->bType,
|
||||
(proto->dwFlags & ITEM_FLAG_STACKABLE) != 0,
|
||||
(proto->dwAntiFlags & ITEM_ANTIFLAG_STACK) != 0, dwVnum);
|
||||
if ((PortMaterialStackPolicy::LegacyGrowthMode() || quest::CQuestManager::instance().GetEventFlag("material_stack_legacy_mode"))) limit=std::min(limit,200u);
|
||||
DWORD remaining=dwEarnCount;
|
||||
while(remaining) {
|
||||
LPITEM item=ITEM_MANAGER::Instance().CreateItem(dwVnum,MIN(remaining,ITEM_MAX_COUNT));
|
||||
LPITEM item=ITEM_MANAGER::Instance().CreateItem(dwVnum,MIN(remaining,limit));
|
||||
if(!item) { --returnCount; break; }
|
||||
const DWORD created=item->GetCount();
|
||||
DWORD count=created;
|
||||
|
||||
@@ -20,7 +20,7 @@ static const Ava2TicketOffer kAva2Tickets[]={
|
||||
struct Ava2ShopPrice { DWORD vnum,count; };
|
||||
struct Ava2ShopStart { TPacketGCShopStart shop; Ava2ShopPrice prices[SHOP_HOST_ITEM_MAX_NUM]; };
|
||||
#pragma pack(pop)
|
||||
static_assert(sizeof(Ava2ShopStart)==2204,"native currency shop payload");
|
||||
static_assert(sizeof(Ava2ShopStart)==2244,"native currency shop payload");
|
||||
static_assert(sizeof(Ava2ShopPrice)==8,"AVA2 item price layout");
|
||||
class CAva2TicketShop : public CShop {
|
||||
public:
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
#include "sectree.h"
|
||||
#include "ani.h"
|
||||
#include "locale_service.h"
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
#include "sectree_manager.h"
|
||||
#endif
|
||||
|
||||
int battle_hit(LPCHARACTER ch, LPCHARACTER victim, int & iRetDam);
|
||||
|
||||
@@ -101,6 +104,12 @@ bool battle_is_attackable(LPCHARACTER ch, LPCHARACTER victim)
|
||||
if (CArenaManager::instance().CanAttack(ch, victim) == true)
|
||||
return true;
|
||||
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
// conqueror maps: a player without a conqueror level cannot fight the monsters there
|
||||
if (ch->IsPC() && !victim->IsPC() && ch->IsConquerorMap(ch->GetMapIndex()) && ch->GetConquerorLevel() == 0)
|
||||
return false;
|
||||
#endif
|
||||
|
||||
return CPVPManager::instance().CanAttack(ch, victim);
|
||||
}
|
||||
|
||||
@@ -337,6 +346,11 @@ int CalcAttBonus(LPCHARACTER pkAttacker, LPCHARACTER pkVictim, int iAtk)
|
||||
case JOB_SHAMAN:
|
||||
iAtk += (iAtk * pkAttacker->GetPoint(POINT_ATTBONUS_SHAMAN)) / 100;
|
||||
break;
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case JOB_WOLFMAN: // TODO: 수인족 ATTBONUS 처리
|
||||
iAtk += (iAtk * pkAttacker->GetPoint(POINT_ATTBONUS_WOLFMAN)) / 100;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,6 +373,11 @@ int CalcAttBonus(LPCHARACTER pkAttacker, LPCHARACTER pkVictim, int iAtk)
|
||||
case JOB_SHAMAN:
|
||||
iAtk -= (iAtk * pkVictim->GetPoint(POINT_RESIST_SHAMAN)) / 100;
|
||||
break;
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case JOB_WOLFMAN: // TODO: 수인족 저항 처리
|
||||
iAtk -= (iAtk * pkVictim->GetPoint(POINT_RESIST_WOLFMAN)) / 100;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -436,6 +455,9 @@ int CalcMeleeDamage(LPCHARACTER pkAttacker, LPCHARACTER pkVictim, bool bIgnoreDe
|
||||
case WEAPON_BELL:
|
||||
case WEAPON_FAN:
|
||||
case WEAPON_MOUNT_SPEAR:
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case WEAPON_CLAW:
|
||||
#endif
|
||||
break;
|
||||
|
||||
case WEAPON_BOW:
|
||||
@@ -666,6 +688,13 @@ void NormalAttackAffect(LPCHARACTER pkAttacker, LPCHARACTER pkVictim)
|
||||
pkVictim->AttackedByPoison(pkAttacker);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
if (pkAttacker->GetPoint(POINT_BLEEDING_PCT) && !pkVictim->IsAffectFlag(AFF_BLEEDING))
|
||||
{
|
||||
if (number(1, 100) <= pkAttacker->GetPoint(POINT_BLEEDING_PCT))
|
||||
pkVictim->AttackedByBleeding(pkAttacker);
|
||||
}
|
||||
#endif
|
||||
int iStunDuration = 2;
|
||||
if (pkAttacker->IsPC() && !pkVictim->IsPC())
|
||||
iStunDuration = 4;
|
||||
@@ -717,6 +746,14 @@ int battle_hit(LPCHARACTER pkAttacker, LPCHARACTER pkVictim, int & iRetDam)
|
||||
case WEAPON_BOW:
|
||||
iDam = iDam * (100 - pkVictim->GetPoint(POINT_RESIST_BOW)) / 100;
|
||||
break;
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case WEAPON_CLAW:
|
||||
//iDam = iDam * (100 - pkVictim->GetPoint(POINT_RESIST_CLAW)) / 100;
|
||||
//#if defined(ENABLE_WOLFMAN_CHARACTER) && defined(USE_ITEM_CLAW_AS_DAGGER)
|
||||
iDam = iDam * (100 - pkVictim->GetPoint(POINT_RESIST_DAGGER)) / 100;
|
||||
//#endif
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -756,6 +793,10 @@ DWORD GET_ATTACK_SPEED(LPCHARACTER ch)
|
||||
if (item && item->GetSubType() == WEAPON_DAGGER)
|
||||
real_speed /= 2;
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
else if (item && item->GetSubType() == WEAPON_CLAW)
|
||||
real_speed /= 2;
|
||||
#endif
|
||||
return real_speed;
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
#include "../../common/VnumHelper.h"
|
||||
|
||||
#include "char.h"
|
||||
#include "sectree_manager.h"
|
||||
#include "port_gaya.h"
|
||||
#include "port_cube_actor.h"
|
||||
#include "../../common/cube_mutation.h"
|
||||
#ifdef ENABLE_OFFLINESHOP_SYSTEM
|
||||
#include "offline_shop.h"
|
||||
#endif
|
||||
@@ -70,6 +73,10 @@
|
||||
#include "PetSystem.h"
|
||||
#endif
|
||||
#include "DragonSoul.h"
|
||||
#include "item.h"
|
||||
#include "port_quiver.h"
|
||||
#include "port_quiver_sync.inc"
|
||||
#include "port_cheque.h"
|
||||
|
||||
extern const BYTE g_aBuffOnAttrPoints;
|
||||
extern bool RaceToJob(unsigned race, unsigned *ret_job);
|
||||
@@ -137,6 +144,7 @@ CHARACTER::~CHARACTER()
|
||||
|
||||
void CHARACTER::Initialize()
|
||||
{
|
||||
m_portQuiverSync=false;
|
||||
CEntity::Initialize(ENTITY_CHARACTER);
|
||||
|
||||
m_bNoOpenedShop = true;
|
||||
@@ -144,6 +152,9 @@ void CHARACTER::Initialize()
|
||||
m_bOpeningSafebox = false;
|
||||
|
||||
m_fSyncTime = get_float_time()-3;
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
m_pkCheonunEvent = NULL;
|
||||
#endif
|
||||
m_dwPlayerID = 0;
|
||||
m_dwKillerPID = 0;
|
||||
|
||||
@@ -192,6 +203,9 @@ void CHARACTER::Initialize()
|
||||
// END_OF_MINING
|
||||
|
||||
m_pkPoisonEvent = NULL;
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
m_pkBleedingEvent = NULL;
|
||||
#endif
|
||||
m_pkFireEvent = NULL;
|
||||
m_pkCheckSpeedHackEvent = NULL;
|
||||
m_speed_hack_count = 0;
|
||||
@@ -261,6 +275,9 @@ void CHARACTER::Initialize()
|
||||
|
||||
m_bHasPoisoned = false;
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
m_bHasBled = false;
|
||||
#endif
|
||||
m_pkDungeon = NULL;
|
||||
m_iEventAttr = 0;
|
||||
|
||||
@@ -422,11 +439,15 @@ void CHARACTER::Create(const char * c_pszName, DWORD vid, bool isPC)
|
||||
m_vid = VID(vid, GetCRC32(crc_string, strlen(crc_string)));
|
||||
|
||||
if (isPC)
|
||||
{
|
||||
m_stName = c_pszName;
|
||||
m_pointsInstant.pItemCells = M2_NEW CHARACTER_ITEM_CELLS();
|
||||
}
|
||||
}
|
||||
|
||||
void CHARACTER::Destroy()
|
||||
{
|
||||
PortCubeActorForget(this);
|
||||
PortGayaForgetPlayer(GetPlayerID());
|
||||
CloseMyShop();
|
||||
|
||||
@@ -541,6 +562,9 @@ void CHARACTER::Destroy()
|
||||
m_set_pkChrSpawnedBy.clear();
|
||||
|
||||
StopMuyeongEvent();
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
StopCheonunEvent();
|
||||
#endif
|
||||
event_cancel(&m_pkWarpNPCEvent);
|
||||
event_cancel(&m_pkRecoveryEvent);
|
||||
event_cancel(&m_pkDeadEvent);
|
||||
@@ -549,6 +573,9 @@ void CHARACTER::Destroy()
|
||||
event_cancel(&m_pkStunEvent);
|
||||
event_cancel(&m_pkFishingEvent);
|
||||
event_cancel(&m_pkPoisonEvent);
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
event_cancel(&m_pkBleedingEvent);
|
||||
#endif
|
||||
event_cancel(&m_pkFireEvent);
|
||||
event_cancel(&m_pkPartyRequestEvent);
|
||||
//DELAYED_WARP
|
||||
@@ -600,6 +627,12 @@ void CHARACTER::Destroy()
|
||||
|
||||
if (m_bMonsterLog)
|
||||
CHARACTER_MANAGER::instance().UnregisterForMonsterLog(this);
|
||||
|
||||
if (m_pointsInstant.pItemCells)
|
||||
{
|
||||
M2_DELETE(m_pointsInstant.pItemCells);
|
||||
m_pointsInstant.pItemCells = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
const char * CHARACTER::GetName() const
|
||||
@@ -607,7 +640,7 @@ const char * CHARACTER::GetName() const
|
||||
return m_stName.empty() ? (m_pkMobData ? m_pkMobData->m_table.szLocaleName : "") : m_stName.c_str();
|
||||
}
|
||||
|
||||
void CHARACTER::OpenMyShop(const char * c_pszSign, TShopItemTable * pTable, BYTE bItemCount)
|
||||
void CHARACTER::OpenMyShop(const char * c_pszSign, TShopItemTable * pTable, BYTE bItemCount, const int32_t * pCheque)
|
||||
{
|
||||
if (GetPart(PART_MAIN) > 2)
|
||||
{
|
||||
@@ -636,7 +669,9 @@ void CHARACTER::OpenMyShop(const char * c_pszSign, TShopItemTable * pTable, BYTE
|
||||
for (int n = 0; n < bItemCount; ++n)
|
||||
{
|
||||
const int64_t price = pTable[n].price;
|
||||
if (price <= 0 || !PortGoldCanChange(nTotalMoney, price, GOLD_MAX_64))
|
||||
const int32_t cheque = pCheque ? pCheque[n] : 0; // PORT: Won price, may stand alone
|
||||
if (price < 0 || cheque < 0 || cheque > CHEQUE_MAX || (price == 0 && cheque == 0) ||
|
||||
!PortGoldCanChange(nTotalMoney, price, GOLD_MAX_64))
|
||||
{
|
||||
ChatPacket(CHAT_TYPE_INFO, "Invalid shop price or gold limit exceeded.");
|
||||
return;
|
||||
@@ -772,7 +807,7 @@ void CHARACTER::OpenMyShop(const char * c_pszSign, TShopItemTable * pTable, BYTE
|
||||
|
||||
PacketAround(&p, sizeof(TPacketGCShopSign));
|
||||
|
||||
m_pkMyShop = CShopManager::instance().CreatePCShop(this, pTable, bItemCount);
|
||||
m_pkMyShop = CShopManager::instance().CreatePCShop(this, pTable, bItemCount, pCheque);
|
||||
|
||||
if (IsPolymorphed() == true)
|
||||
{
|
||||
@@ -950,6 +985,9 @@ void CHARACTER::EncodeInsertPacket(LPENTITY entity)
|
||||
{
|
||||
addPacket.dwLevel = 0;
|
||||
}
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
addPacket.dwConquerorLevel = IsPC() ? GetConquerorLevel() : 0;
|
||||
#endif
|
||||
|
||||
if (false)
|
||||
{
|
||||
@@ -984,6 +1022,7 @@ void CHARACTER::EncodeInsertPacket(LPENTITY entity)
|
||||
}
|
||||
|
||||
d->Packet(&addPacket, sizeof(TPacketGCCharacterAdditionalInfo));
|
||||
PortSendQuiverState(ch);
|
||||
}
|
||||
|
||||
if (iDur)
|
||||
@@ -1075,6 +1114,9 @@ void CHARACTER::UpdatePacket()
|
||||
pack.dwAffectFlag[1] = m_afAffectFlag.bits[1];
|
||||
pack.dwGuildID = 0;
|
||||
pack.sAlignment = m_iAlignment / 10;
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
pack.dwConquerorLevel = IsPC() ? GetConquerorLevel() : 0;
|
||||
#endif
|
||||
pack.bPKMode = m_bPKMode;
|
||||
|
||||
if (GetGuild())
|
||||
@@ -1132,6 +1174,7 @@ void CHARACTER::UpdatePacket()
|
||||
{
|
||||
PacketAround(&pack, sizeof(pack));
|
||||
}
|
||||
PortBroadcastQuiverState();
|
||||
}
|
||||
|
||||
LPCHARACTER CHARACTER::FindCharacterInView(const char * c_pszName, bool bFindPCOnly)
|
||||
@@ -1307,6 +1350,16 @@ void CHARACTER::CreatePlayerProto(TPlayerTable & tab)
|
||||
// REMOVE_REAL_SKILL_LEVLES
|
||||
thecore_memcpy(tab.skills, m_pSkillLevels, sizeof(TPlayerSkill) * SKILL_MAX_NUM);
|
||||
// END_OF_REMOVE_REAL_SKILL_LEVLES
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
tab.conqueror_exp = GetConquerorExp();
|
||||
tab.conquerorlevel = GetConquerorLevel();
|
||||
tab.conqueror_level_step = GetPoint(POINT_CONQUEROR_LEVEL_STEP);
|
||||
tab.sungma_str = GetRealPoint(POINT_SUNGMA_STR);
|
||||
tab.sungma_hp = GetRealPoint(POINT_SUNGMA_HP);
|
||||
tab.sungma_move = GetRealPoint(POINT_SUNGMA_MOVE);
|
||||
tab.sungma_inmune = GetRealPoint(POINT_SUNGMA_INMUNE);
|
||||
tab.conqueror_point = GetPoint(POINT_CONQUEROR_POINT);
|
||||
#endif
|
||||
|
||||
tab.horse = GetHorseData();
|
||||
|
||||
@@ -1364,6 +1417,7 @@ void CHARACTER::FlushDelayedSaveItem()
|
||||
|
||||
void CHARACTER::Disconnect(const char * c_pszReason)
|
||||
{
|
||||
PortCubeAssetMutation(this,PortCube::LifecycleWrite);
|
||||
assert(GetDesc() != NULL);
|
||||
|
||||
sys_log(0, "DISCONNECT: %s (%s)", GetName(), c_pszReason ? c_pszReason : "unset" );
|
||||
@@ -1704,6 +1758,12 @@ void CHARACTER::PointsPacket()
|
||||
for (int i = POINT_ST; i < POINT_MAX_NUM; ++i)
|
||||
pack.points[i] = GetPoint(i);
|
||||
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
pack.points[POINT_CONQUEROR_LEVEL] = GetConquerorLevel();
|
||||
pack.points[POINT_CONQUEROR_EXP] = GetConquerorExp();
|
||||
pack.points[POINT_CONQUEROR_NEXT_EXP] = GetConquerorNextExp();
|
||||
#endif
|
||||
|
||||
GetDesc()->Packet(&pack, sizeof(TPacketGCPoints));
|
||||
|
||||
TPacketGCExtendedPointGold goldPack;
|
||||
@@ -1751,6 +1811,11 @@ bool CHARACTER::ChangeSex()
|
||||
m_points.job = MAIN_RACE_SHAMAN_M;
|
||||
break;
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case MAIN_RACE_WOLFMAN_M:
|
||||
m_points.job = MAIN_RACE_WOLFMAN_M;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
sys_err("CHANGE_SEX: %s unknown race %d", GetName(), src_race);
|
||||
return false;
|
||||
@@ -1889,6 +1954,25 @@ void CHARACTER::SetPlayerProto(const TPlayerTable * t)
|
||||
SetLevel(t->level);
|
||||
SetExp(t->exp);
|
||||
SetGold(t->gold);
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
SetConquerorLevel(t->conquerorlevel);
|
||||
SetConquerorExp(t->conqueror_exp);
|
||||
|
||||
SetPoint(POINT_CONQUEROR_LEVEL_STEP, t->conqueror_level_step);
|
||||
SetRealPoint(POINT_CONQUEROR_LEVEL_STEP, t->conqueror_level_step);
|
||||
|
||||
SetRealPoint(POINT_SUNGMA_STR, t->sungma_str);
|
||||
SetRealPoint(POINT_SUNGMA_HP, t->sungma_hp);
|
||||
SetRealPoint(POINT_SUNGMA_MOVE, t->sungma_move);
|
||||
SetRealPoint(POINT_SUNGMA_INMUNE, t->sungma_inmune);
|
||||
|
||||
SetPoint(POINT_SUNGMA_STR, t->sungma_str);
|
||||
SetPoint(POINT_SUNGMA_HP, t->sungma_hp);
|
||||
SetPoint(POINT_SUNGMA_MOVE, t->sungma_move);
|
||||
SetPoint(POINT_SUNGMA_INMUNE, t->sungma_inmune);
|
||||
SetPoint(POINT_CONQUEROR_POINT, t->conqueror_point);
|
||||
SetRealPoint(POINT_CONQUEROR_POINT, t->conqueror_point);
|
||||
#endif
|
||||
|
||||
SetMapIndex(t->lMapIndex);
|
||||
SetXYZ(t->x, t->y, t->z);
|
||||
@@ -2221,6 +2305,12 @@ void CHARACTER::ComputeBattlePoints()
|
||||
iStatAtk = (4 * GetPoint(POINT_ST) + 2 * GetPoint(POINT_IQ)) / 3;
|
||||
break;
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case JOB_WOLFMAN:
|
||||
// TODO: 수인족 공격력 공식 기획자에게 요청
|
||||
iStatAtk = (2 * GetPoint(POINT_ST));
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
sys_err("invalid job %d", GetJob());
|
||||
iStatAtk = (2 * GetPoint(POINT_ST));
|
||||
@@ -2302,6 +2392,9 @@ void CHARACTER::ComputeBattlePoints()
|
||||
|
||||
PointChange(POINT_MAGIC_ATT_GRADE, GetLevel() * 2 + GetPoint(POINT_IQ) * 2 + GetPoint(POINT_MAGIC_ATT_GRADE_BONUS));
|
||||
PointChange(POINT_MAGIC_DEF_GRADE, GetLevel() + (GetPoint(POINT_IQ) * 3 + GetPoint(POINT_HT)) / 3 + iArmor / 2 + GetPoint(POINT_MAGIC_DEF_GRADE_BONUS));
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
PointChange(POINT_MOV_SPEED, 0); // conqueror maps clamp the move speed by sungma_move
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2321,6 +2414,7 @@ void CHARACTER::ComputePoints()
|
||||
{
|
||||
long lStat = GetPoint(POINT_STAT);
|
||||
const int lGem=GetPoint(POINT_GEM);
|
||||
const int lCheque=GetPoint(POINT_CHEQUE);
|
||||
long lStatResetCount = GetPoint(POINT_STAT_RESET_COUNT);
|
||||
long lSkillActive = GetPoint(POINT_SKILL);
|
||||
long lSkillSub = GetPoint(POINT_SUB_SKILL);
|
||||
@@ -2336,6 +2430,10 @@ void CHARACTER::ComputePoints()
|
||||
|
||||
long lHPRecovery = GetPoint(POINT_HP_RECOVERY);
|
||||
long lSPRecovery = GetPoint(POINT_SP_RECOVERY);
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
long lConquerorStat = GetPoint(POINT_CONQUEROR_POINT);
|
||||
long lConquerorLevelStep = GetPoint(POINT_CONQUEROR_LEVEL_STEP);
|
||||
#endif
|
||||
|
||||
memset(m_pointsInstant.points, 0, sizeof(m_pointsInstant.points));
|
||||
BuffOnAttr_ClearAll();
|
||||
@@ -2343,6 +2441,7 @@ void CHARACTER::ComputePoints()
|
||||
|
||||
SetPoint(POINT_STAT, lStat);
|
||||
SetPoint(POINT_GEM,lGem);
|
||||
SetPoint(POINT_CHEQUE,lCheque);
|
||||
SetPoint(POINT_SKILL, lSkillActive);
|
||||
SetPoint(POINT_SUB_SKILL, lSkillSub);
|
||||
SetPoint(POINT_HORSE_SKILL, lSkillHorse);
|
||||
@@ -2353,6 +2452,15 @@ void CHARACTER::ComputePoints()
|
||||
SetPoint(POINT_HT, GetRealPoint(POINT_HT));
|
||||
SetPoint(POINT_DX, GetRealPoint(POINT_DX));
|
||||
SetPoint(POINT_IQ, GetRealPoint(POINT_IQ));
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
SetPoint(POINT_CONQUEROR_POINT, lConquerorStat);
|
||||
SetPoint(POINT_CONQUEROR_LEVEL_STEP, lConquerorLevelStep);
|
||||
|
||||
SetPoint(POINT_SUNGMA_STR, GetRealPoint(POINT_SUNGMA_STR));
|
||||
SetPoint(POINT_SUNGMA_HP, GetRealPoint(POINT_SUNGMA_HP));
|
||||
SetPoint(POINT_SUNGMA_MOVE, GetRealPoint(POINT_SUNGMA_MOVE));
|
||||
SetPoint(POINT_SUNGMA_INMUNE, GetRealPoint(POINT_SUNGMA_INMUNE));
|
||||
#endif
|
||||
|
||||
SetPart(PART_MAIN, GetOriginalPart(PART_MAIN));
|
||||
SetPart(PART_WEAPON, GetOriginalPart(PART_WEAPON));
|
||||
@@ -2542,6 +2650,10 @@ EVENTFUNC(recovery_event)
|
||||
if (ch->IsAffectFlag(AFF_POISON))
|
||||
return PASSES_PER_SEC(MAX(1, ch->GetMobTable().bRegenCycle));
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
if (ch->IsAffectFlag(AFF_BLEEDING))
|
||||
return PASSES_PER_SEC(MAX(1, ch->GetMobTable().bRegenCycle));
|
||||
#endif
|
||||
if (2493 == ch->GetMobTable().dwVnum)
|
||||
{
|
||||
int regenPct = BlueDragon_GetRangeFactor("hp_regen", ch->GetHPPct());
|
||||
@@ -2607,6 +2719,10 @@ EVENTFUNC(recovery_event)
|
||||
// 파법술인 경우 자동회복 금지
|
||||
return 3;
|
||||
}
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
if (ch->IsAffectFlag(AFF_BLEEDING))
|
||||
return 3;
|
||||
#endif
|
||||
|
||||
int iSec = (get_dword_time() - ch->GetLastMoveTime()) / 3000;
|
||||
|
||||
@@ -2877,6 +2993,11 @@ DWORD CHARACTER::GetMotionMode() const
|
||||
case WEAPON_FAN:
|
||||
dwMode = MOTION_MODE_FAN;
|
||||
break;
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case WEAPON_CLAW:
|
||||
dwMode = MOTION_MODE_CLAW;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return dwMode;
|
||||
@@ -3129,6 +3250,7 @@ void CHARACTER::CheckMaximumPoints()
|
||||
|
||||
void CHARACTER::PointChange(BYTE type, int64_t amount, bool bAmount, bool bBroadcast)
|
||||
{
|
||||
if(type==POINT_GOLD&&amount)PortCubeAssetMutation(this,PortCube::GoldWrite);
|
||||
int val = 0;
|
||||
|
||||
//sys_log(0, "PointChange %d %d | %d -> %d cHP %d mHP %d", type, amount, GetPoint(type), GetPoint(type)+amount, GetHP(), GetMaxHP());
|
||||
@@ -3138,6 +3260,146 @@ void CHARACTER::PointChange(BYTE type, int64_t amount, bool bAmount, bool bBroad
|
||||
case POINT_NONE:
|
||||
return;
|
||||
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
case POINT_CONQUEROR_LEVEL:
|
||||
if ((GetConquerorLevel() + amount) > gPlayerConquerorMaxLevel)
|
||||
return;
|
||||
|
||||
SetConquerorLevel(GetConquerorLevel() + amount);
|
||||
val = GetConquerorLevel();
|
||||
|
||||
sys_log(0, "CONQUEROR_LEVELUP: %s %d NEXT EXP %d", GetName(), GetConquerorLevel(), GetConquerorNextExp());
|
||||
// PORT: AVA2 also copies the wolfman level-5 skill-group reset here; it keys off the
|
||||
// conqueror level by mistake, so it is left out.
|
||||
PointChange(POINT_CONQUEROR_NEXT_EXP, GetConquerorNextExp(), false);
|
||||
break;
|
||||
|
||||
case POINT_CONQUEROR_NEXT_EXP:
|
||||
val = GetConquerorNextExp();
|
||||
bAmount = false;
|
||||
break;
|
||||
|
||||
case POINT_CONQUEROR_EXP:
|
||||
{
|
||||
DWORD exp = GetConquerorExp();
|
||||
DWORD next_exp = GetConquerorNextExp();
|
||||
|
||||
if (amount < 0 && exp < -amount)
|
||||
{
|
||||
sys_log(1, "%s AMOUNT < 0 %d, CUR CONQUEROR EXP: %d", GetName(), -amount, exp);
|
||||
amount = -exp;
|
||||
|
||||
SetConquerorExp(exp + amount);
|
||||
val = GetConquerorExp();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gPlayerConquerorMaxLevel <= GetConquerorLevel())
|
||||
return;
|
||||
|
||||
if (test_server)
|
||||
ChatPacket(CHAT_TYPE_INFO, "You have gained %d conqueror exp.", amount);
|
||||
|
||||
DWORD iExpBalance = 0;
|
||||
|
||||
const unsigned long long total = (unsigned long long) exp + (unsigned long long) amount;
|
||||
if (total >= next_exp)
|
||||
{
|
||||
iExpBalance = (DWORD) (total - next_exp);
|
||||
amount = next_exp - exp;
|
||||
|
||||
SetConquerorExp(0);
|
||||
exp = next_exp;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetConquerorExp((DWORD) total);
|
||||
exp = GetConquerorExp();
|
||||
}
|
||||
|
||||
DWORD q = DWORD(next_exp / 4.0f);
|
||||
int iLevStep = GetRealPoint(POINT_CONQUEROR_LEVEL_STEP);
|
||||
|
||||
if (iLevStep >= 4)
|
||||
{
|
||||
sys_err("%s CONQUEROR_LEVEL_STEP bigger than 4! (%d)", GetName(), iLevStep);
|
||||
iLevStep = 4;
|
||||
}
|
||||
|
||||
if (exp >= next_exp && iLevStep < 4)
|
||||
{
|
||||
for (int i = 0; i < 4 - iLevStep; ++i)
|
||||
PointChange(POINT_CONQUEROR_LEVEL_STEP, 1, false, true);
|
||||
}
|
||||
else if (exp >= q * 3 && iLevStep < 3)
|
||||
{
|
||||
for (int i = 0; i < 3 - iLevStep; ++i)
|
||||
PointChange(POINT_CONQUEROR_LEVEL_STEP, 1, false, true);
|
||||
}
|
||||
else if (exp >= q * 2 && iLevStep < 2)
|
||||
{
|
||||
for (int i = 0; i < 2 - iLevStep; ++i)
|
||||
PointChange(POINT_CONQUEROR_LEVEL_STEP, 1, false, true);
|
||||
}
|
||||
else if (exp >= q && iLevStep < 1)
|
||||
PointChange(POINT_CONQUEROR_LEVEL_STEP, 1);
|
||||
|
||||
if (iExpBalance)
|
||||
{
|
||||
PointChange(POINT_CONQUEROR_EXP, iExpBalance);
|
||||
}
|
||||
|
||||
val = GetConquerorExp();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case POINT_CONQUEROR_LEVEL_STEP:
|
||||
if (amount > 0)
|
||||
{
|
||||
val = GetPoint(POINT_CONQUEROR_LEVEL_STEP) + amount;
|
||||
|
||||
switch (val)
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
if (GetConquerorLevel() <= gPlayerConquerorMaxLevel)
|
||||
PointChange(POINT_CONQUEROR_POINT, 1);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
PointChange(POINT_CONQUEROR_LEVEL, 1, false, true);
|
||||
val = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
SetPoint(POINT_CONQUEROR_LEVEL_STEP, val);
|
||||
SetRealPoint(POINT_CONQUEROR_LEVEL_STEP, val);
|
||||
|
||||
Save();
|
||||
}
|
||||
else
|
||||
val = GetPoint(POINT_CONQUEROR_LEVEL_STEP);
|
||||
|
||||
break;
|
||||
|
||||
case POINT_SUNGMA_STR:
|
||||
case POINT_SUNGMA_HP:
|
||||
case POINT_SUNGMA_MOVE:
|
||||
case POINT_SUNGMA_INMUNE:
|
||||
SetPoint(type, GetPoint(type) + amount);
|
||||
val = GetPoint(type);
|
||||
break;
|
||||
|
||||
case POINT_CONQUEROR_POINT:
|
||||
SetPoint(type, GetPoint(type) + amount);
|
||||
val = GetPoint(type);
|
||||
|
||||
SetRealPoint(type, val);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case POINT_LEVEL:
|
||||
if ((GetLevel() + amount) > gPlayerMaxLevel)
|
||||
return;
|
||||
@@ -3147,6 +3409,24 @@ void CHARACTER::PointChange(BYTE type, int64_t amount, bool bAmount, bool bBroad
|
||||
|
||||
sys_log(0, "LEVELUP: %s %d NEXT EXP %d", GetName(), GetLevel(), GetNextExp());
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
if (GetJob() == JOB_WOLFMAN)
|
||||
{
|
||||
if ((5 <= val) && (GetSkillGroup()!=1))
|
||||
{
|
||||
ClearSkill();
|
||||
// set skill group
|
||||
SetSkillGroup(1);
|
||||
// set skill points
|
||||
SetRealPoint(POINT_SKILL, GetLevel()-1);
|
||||
SetPoint(POINT_SKILL, GetRealPoint(POINT_SKILL));
|
||||
PointChange(POINT_SKILL, 0);
|
||||
// update points (not required)
|
||||
// ComputePoints();
|
||||
// PointsPacket();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
PointChange(POINT_NEXT_EXP, GetNextExp(), false);
|
||||
|
||||
if (amount)
|
||||
@@ -3403,6 +3683,12 @@ void CHARACTER::PointChange(BYTE type, int64_t amount, bool bAmount, bool bBroad
|
||||
add_hp += GetPoint(POINT_PARTY_TANKER_BONUS);
|
||||
|
||||
SetMaxHP(hp + add_hp);
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
// conqueror maps: half the bonus HP below the map's sungma_hp requirement
|
||||
if (IsPC() && IsConquerorMap(GetMapIndex()) &&
|
||||
GetPoint(POINT_SUNGMA_HP) < SECTREE_MANAGER::instance().GetSungmaValueAffectByRegion(GetMapIndex(), AFFECT_SUNGMA_HP))
|
||||
SetMaxHP(hp + add_hp / 2);
|
||||
#endif
|
||||
|
||||
val = GetMaxHP();
|
||||
}
|
||||
@@ -3450,6 +3736,11 @@ void CHARACTER::PointChange(BYTE type, int64_t amount, bool bAmount, bool bBroad
|
||||
val=GetPoint(type);
|
||||
break;
|
||||
|
||||
case POINT_CHEQUE: // display only: PortChequeChange owns the balance
|
||||
if(amount)return;
|
||||
val=GetPoint(type);
|
||||
break;
|
||||
|
||||
case POINT_GOLD:
|
||||
{
|
||||
if (!PortGoldCanChange(GetGold(),amount,GOLD_MAX_64)) {
|
||||
@@ -3504,6 +3795,22 @@ void CHARACTER::PointChange(BYTE type, int64_t amount, bool bAmount, bool bBroad
|
||||
val = GetPoint(type);
|
||||
break;
|
||||
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
case POINT_MOV_SPEED:
|
||||
// AVA2: on a conqueror map the move speed is pinned to 140 below the sungma_move requirement, 209 above it
|
||||
if (IsPC() && IsConquerorMap(GetMapIndex()))
|
||||
{
|
||||
if (GetPoint(POINT_SUNGMA_MOVE) < SECTREE_MANAGER::instance().GetSungmaValueAffectByRegion(GetMapIndex(), AFFECT_SUNGMA_MOVE))
|
||||
SetPoint(type, 140);
|
||||
else
|
||||
SetPoint(type, 209);
|
||||
}
|
||||
|
||||
SetPoint(type, GetPoint(type) + amount);
|
||||
val = GetPoint(type);
|
||||
break;
|
||||
|
||||
#endif
|
||||
case POINT_ST:
|
||||
case POINT_HT:
|
||||
case POINT_DX:
|
||||
@@ -3512,7 +3819,9 @@ void CHARACTER::PointChange(BYTE type, int64_t amount, bool bAmount, bool bBroad
|
||||
case POINT_SP_REGEN:
|
||||
case POINT_ATT_SPEED:
|
||||
case POINT_ATT_GRADE:
|
||||
#ifndef ENABLE_CONQUEROR_LEVEL
|
||||
case POINT_MOV_SPEED:
|
||||
#endif
|
||||
case POINT_CASTING_SPEED:
|
||||
case POINT_MAGIC_ATT_GRADE:
|
||||
case POINT_MAGIC_DEF_GRADE:
|
||||
@@ -3528,6 +3837,9 @@ void CHARACTER::PointChange(BYTE type, int64_t amount, bool bAmount, bool bBroad
|
||||
case POINT_ATTBONUS_DEVIL: // 47 마귀(악마)에게 데미지 % 증가
|
||||
|
||||
// PORT AVA2 biology points
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case POINT_ATTBONUS_CLAW:
|
||||
#endif
|
||||
case POINT_ATTBONUS_STONE:
|
||||
case POINT_ATTBONUS_BOSS:
|
||||
case POINT_ENCHANT_ELEC:
|
||||
@@ -3542,8 +3854,14 @@ void CHARACTER::PointChange(BYTE type, int64_t amount, bool bAmount, bool bBroad
|
||||
case POINT_ATTBONUS_ASSASSIN:
|
||||
case POINT_ATTBONUS_WARRIOR:
|
||||
case POINT_ATTBONUS_SHAMAN:
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case POINT_ATTBONUS_WOLFMAN:
|
||||
#endif
|
||||
|
||||
case POINT_POISON_PCT:
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case POINT_BLEEDING_PCT:
|
||||
#endif
|
||||
case POINT_STUN_PCT:
|
||||
case POINT_SLOW_PCT:
|
||||
|
||||
@@ -3568,6 +3886,9 @@ void CHARACTER::PointChange(BYTE type, int64_t amount, bool bAmount, bool bBroad
|
||||
case POINT_RESIST_BELL:
|
||||
case POINT_RESIST_FAN:
|
||||
case POINT_RESIST_BOW:
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case POINT_RESIST_CLAW:
|
||||
#endif
|
||||
case POINT_RESIST_FIRE:
|
||||
case POINT_RESIST_ELEC:
|
||||
case POINT_RESIST_MAGIC:
|
||||
@@ -3579,6 +3900,9 @@ void CHARACTER::PointChange(BYTE type, int64_t amount, bool bAmount, bool bBroad
|
||||
case POINT_REFLECT_MELEE: // 67 공격 반사
|
||||
case POINT_REFLECT_CURSE: // 68 저주 반사
|
||||
case POINT_POISON_REDUCE: // 69 독데미지 감소
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case POINT_BLEEDING_REDUCE:
|
||||
#endif
|
||||
case POINT_KILL_SP_RECOVER: // 70 적 소멸시 MP 회복
|
||||
case POINT_KILL_HP_RECOVERY: // 75
|
||||
case POINT_HIT_HP_RECOVERY:
|
||||
@@ -3608,6 +3932,9 @@ void CHARACTER::PointChange(BYTE type, int64_t amount, bool bAmount, bool bBroad
|
||||
case POINT_RESIST_ASSASSIN :
|
||||
case POINT_RESIST_SURA :
|
||||
case POINT_RESIST_SHAMAN :
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case POINT_RESIST_WOLFMAN :
|
||||
#endif
|
||||
|
||||
SetPoint(type, GetPoint(type) + amount);
|
||||
val = GetPoint(type);
|
||||
@@ -3755,6 +4082,13 @@ void CHARACTER::PointChange(BYTE type, int64_t amount, bool bAmount, bool bBroad
|
||||
case POINT_DX:
|
||||
case POINT_IQ:
|
||||
case POINT_HT:
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
case POINT_CONQUEROR_LEVEL:
|
||||
case POINT_SUNGMA_STR:
|
||||
case POINT_SUNGMA_HP:
|
||||
case POINT_SUNGMA_MOVE:
|
||||
case POINT_SUNGMA_INMUNE:
|
||||
#endif
|
||||
ComputeBattlePoints();
|
||||
break;
|
||||
case POINT_MAX_HP:
|
||||
@@ -3852,6 +4186,9 @@ void CHARACTER::ApplyPoint(BYTE bApplyType, int iVal)
|
||||
case APPLY_HP_REGEN:
|
||||
case APPLY_SP_REGEN:
|
||||
case APPLY_POISON_PCT:
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case APPLY_BLEEDING_PCT:
|
||||
#endif
|
||||
case APPLY_STUN_PCT:
|
||||
case APPLY_SLOW_PCT:
|
||||
case APPLY_CRITICAL_PCT:
|
||||
@@ -3866,6 +4203,9 @@ void CHARACTER::ApplyPoint(BYTE bApplyType, int iVal)
|
||||
case APPLY_ATTBONUS_ASSASSIN: // 60
|
||||
case APPLY_ATTBONUS_SURA: // 61
|
||||
case APPLY_ATTBONUS_SHAMAN: // 62
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case APPLY_ATTBONUS_WOLFMAN:
|
||||
#endif
|
||||
case APPLY_ATTBONUS_MONSTER: // 63
|
||||
case APPLY_STEAL_HP:
|
||||
case APPLY_STEAL_SP:
|
||||
@@ -3879,6 +4219,9 @@ void CHARACTER::ApplyPoint(BYTE bApplyType, int iVal)
|
||||
case APPLY_RESIST_BELL:
|
||||
case APPLY_RESIST_FAN:
|
||||
case APPLY_RESIST_BOW:
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case APPLY_RESIST_CLAW:
|
||||
#endif
|
||||
case APPLY_RESIST_FIRE:
|
||||
case APPLY_RESIST_ELEC:
|
||||
case APPLY_RESIST_MAGIC:
|
||||
@@ -3892,6 +4235,9 @@ void CHARACTER::ApplyPoint(BYTE bApplyType, int iVal)
|
||||
case APPLY_ANTI_CRITICAL_PCT:
|
||||
case APPLY_ANTI_PENETRATE_PCT:
|
||||
case APPLY_POISON_REDUCE:
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case APPLY_BLEEDING_REDUCE:
|
||||
#endif
|
||||
case APPLY_KILL_SP_RECOVER:
|
||||
case APPLY_EXP_DOUBLE_BONUS:
|
||||
case APPLY_GOLD_DOUBLE_BONUS:
|
||||
@@ -3928,12 +4274,24 @@ void CHARACTER::ApplyPoint(BYTE bApplyType, int iVal)
|
||||
case APPLY_RESIST_ASSASSIN :
|
||||
case APPLY_RESIST_SURA :
|
||||
case APPLY_RESIST_SHAMAN :
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case APPLY_RESIST_WOLFMAN :
|
||||
#endif
|
||||
case APPLY_ENERGY: // 82 기력
|
||||
case APPLY_DEF_GRADE: // 83 방어력. DEF_GRADE_BONUS는 클라에서 두배로 보여지는 의도된 버그(...)가 있다.
|
||||
case APPLY_COSTUME_ATTR_BONUS: // 84 코스튬 아이템에 붙은 속성치 보너스
|
||||
case APPLY_MAGIC_ATTBONUS_PER: // 85 마법 공격력 +x%
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case APPLY_ATTBONUS_CLAW: //115
|
||||
#endif
|
||||
case APPLY_ATTBONUS_STONE:
|
||||
case APPLY_ATTBONUS_BOSS:
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
case APPLY_SUNGMA_STR:
|
||||
case APPLY_SUNGMA_HP:
|
||||
case APPLY_SUNGMA_MOVE:
|
||||
case APPLY_SUNGMA_INMUNE:
|
||||
#endif
|
||||
case APPLY_ENCHANT_ELEC:
|
||||
case APPLY_ENCHANT_FIRE:
|
||||
case APPLY_ENCHANT_ICE:
|
||||
@@ -5391,6 +5749,7 @@ bool CHARACTER::WarpSet(long x, long y, long lPrivateMapIndex)
|
||||
|
||||
bool CHARACTER::WarpSet(long x, long y, long lPrivateMapIndex, BYTE targetChannel)
|
||||
{
|
||||
PortCubeAssetMutation(this,PortCube::LifecycleWrite);
|
||||
if (!IsPC())
|
||||
return false;
|
||||
|
||||
@@ -6385,7 +6744,11 @@ int CHARACTER::GetPolymorphPower() const
|
||||
|
||||
void CHARACTER::SetPolymorph(DWORD dwRaceNum, bool bMaintainStat)
|
||||
{
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
if (dwRaceNum < MAIN_RACE_MAX_NUM)
|
||||
#else
|
||||
if (dwRaceNum < JOB_MAX_NUM)
|
||||
#endif
|
||||
{
|
||||
dwRaceNum = 0;
|
||||
bMaintainStat = false;
|
||||
@@ -7080,6 +7443,9 @@ ESex GET_SEX(LPCHARACTER ch)
|
||||
case MAIN_RACE_SURA_M:
|
||||
case MAIN_RACE_ASSASSIN_M:
|
||||
case MAIN_RACE_SHAMAN_M:
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case MAIN_RACE_WOLFMAN_M:
|
||||
#endif
|
||||
return SEX_MALE;
|
||||
|
||||
case MAIN_RACE_ASSASSIN_W:
|
||||
@@ -7448,6 +7814,30 @@ bool CHARACTER::CanWarp() const
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
DWORD CHARACTER::GetConquerorNextExp() const
|
||||
{
|
||||
// PORT: AVA2 bounds this by PLAYER_MAX_LEVEL_CONST, which reads past the 31-entry table
|
||||
if (PLAYER_MAX_CONQUEROR_LEVEL_CONST < GetConquerorLevel())
|
||||
return 2500000000u;
|
||||
else
|
||||
return exp_coqueror_table[GetConquerorLevel()];
|
||||
}
|
||||
|
||||
bool CHARACTER::IsConquerorMap(long lMapIndex) const
|
||||
{
|
||||
switch (lMapIndex)
|
||||
{
|
||||
case EASTPLAIN_01:
|
||||
case EASTPLAIN_02:
|
||||
case EASTPLAIN_03:
|
||||
case EMPIRECASTLE:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
DWORD CHARACTER::GetNextExp() const
|
||||
{
|
||||
if (PLAYER_EXP_TABLE_MAX < GetLevel())
|
||||
|
||||
+108
-24
@@ -15,6 +15,8 @@
|
||||
#include "mining.h"
|
||||
|
||||
class CBuffOnAttributes;
|
||||
namespace PortCube {struct InventoryImage;}
|
||||
namespace PortCubeView {struct Frame;}
|
||||
class CPetSystem;
|
||||
#ifdef ENABLE_OFFLINESHOP_SYSTEM
|
||||
class COfflineShop;
|
||||
@@ -47,12 +49,18 @@ enum
|
||||
MAIN_RACE_ASSASSIN_M,
|
||||
MAIN_RACE_SURA_W,
|
||||
MAIN_RACE_SHAMAN_M,
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
MAIN_RACE_WOLFMAN_M,
|
||||
#endif
|
||||
MAIN_RACE_MAX_NUM,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
POISON_LENGTH = 30,
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
BLEEDING_LENGTH = 30,
|
||||
#endif
|
||||
STAMINA_PER_STEP = 1,
|
||||
SAFEBOX_PAGE_SIZE = 9,
|
||||
AI_CHANGE_ATTACK_POISITION_TIME_NEAR = 10000,
|
||||
@@ -80,6 +88,9 @@ enum
|
||||
FLY_CHAIN_LIGHTNING,
|
||||
FLY_HP_SMALL,
|
||||
FLY_SKILL_MUYEONG,
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
FLY_CONQUEROR_EXP,
|
||||
#endif
|
||||
};
|
||||
|
||||
enum EDamageType
|
||||
@@ -96,6 +107,9 @@ enum EDamageType
|
||||
DAMAGE_TYPE_MAGIC,
|
||||
DAMAGE_TYPE_POISON,
|
||||
DAMAGE_TYPE_SPECIAL,
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
DAMAGE_TYPE_BLEEDING,
|
||||
#endif
|
||||
};
|
||||
|
||||
enum EPointTypes
|
||||
@@ -291,6 +305,7 @@ enum EPointTypes
|
||||
POINT_ENCHANT_EARTH = 246,
|
||||
POINT_ENCHANT_DARK = 247,
|
||||
POINT_GEM = 248,
|
||||
POINT_CHEQUE = 249, // PORT: Won, mirrored from quest flag cheque.points
|
||||
POINT_RESIST_HUMAN = 220,
|
||||
POINT_RESIST_MAGIC_REDUCTION = 144, // AVA2 attacker's magic resistance reduction.
|
||||
|
||||
@@ -302,6 +317,28 @@ enum EPointTypes
|
||||
POINT_RESIST_CRITICAL = 136, // 크리티컬 저항 : 상대의 크리티컬 확률을 감소
|
||||
POINT_RESIST_PENETRATE = 137, // 관통타격 저항 : 상대의 관통타격 확률을 감소
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
POINT_BLEEDING_REDUCE = 138,
|
||||
POINT_BLEEDING_PCT = 139,
|
||||
|
||||
POINT_ATTBONUS_WOLFMAN = 140,
|
||||
POINT_RESIST_WOLFMAN = 141,
|
||||
POINT_RESIST_CLAW = 142,
|
||||
POINT_ATTBONUS_CLAW = 239, // PORT: AVA2 auto-numbers it after ATTBONUS_ZODIAC; 239 is free below the 240+ AVA2 ports
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
POINT_CONQUEROR_LEVEL = 205,
|
||||
POINT_CONQUEROR_LEVEL_STEP = 206,
|
||||
POINT_SUNGMA_STR = 207,
|
||||
POINT_SUNGMA_HP = 208,
|
||||
POINT_SUNGMA_MOVE = 209,
|
||||
POINT_SUNGMA_INMUNE = 210,
|
||||
POINT_CONQUEROR_POINT = 211,
|
||||
POINT_CONQUEROR_EXP = 212,
|
||||
POINT_CONQUEROR_NEXT_EXP = 213,
|
||||
#endif
|
||||
|
||||
//POINT_MAX_NUM = 129 common/length.h
|
||||
};
|
||||
|
||||
@@ -378,6 +415,10 @@ typedef struct character_point
|
||||
BYTE voice;
|
||||
|
||||
BYTE level;
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
BYTE conquerorlevel;
|
||||
DWORD conqueror_exp;
|
||||
#endif
|
||||
DWORD exp;
|
||||
int64_t gold;
|
||||
|
||||
@@ -392,6 +433,31 @@ typedef struct character_point
|
||||
BYTE skill_group;
|
||||
} CHARACTER_POINT;
|
||||
|
||||
// MT: the inventory/equipment, dragon soul and special storage cells used to sit in every CHARACTER
|
||||
// (~13 KB). Mobs and NPCs never hold items, so only PCs allocate them; a core keeps ~20k mobs alive.
|
||||
typedef struct character_item_cells
|
||||
{
|
||||
LPITEM pItems[INVENTORY_AND_EQUIP_SLOT_MAX];
|
||||
WORD bItemGrid[INVENTORY_AND_EQUIP_SLOT_MAX]; // MT: BYTE in 40250; holds cell + 1, and cells reach 302
|
||||
|
||||
// 용혼석 인벤토리.
|
||||
LPITEM pDSItems[DRAGON_SOUL_INVENTORY_MAX_NUM];
|
||||
WORD wDSItemGrid[DRAGON_SOUL_INVENTORY_MAX_NUM];
|
||||
|
||||
#ifdef ENABLE_SPECIAL_STORAGE
|
||||
LPITEM pSSUItems[SPECIAL_INVENTORY_MAX_NUM];
|
||||
WORD wSSUItemGrid[SPECIAL_INVENTORY_MAX_NUM];
|
||||
LPITEM pSSBItems[SPECIAL_INVENTORY_MAX_NUM];
|
||||
WORD wSSBItemGrid[SPECIAL_INVENTORY_MAX_NUM];
|
||||
LPITEM pSSSItems[SPECIAL_INVENTORY_MAX_NUM];
|
||||
WORD wSSSItemGrid[SPECIAL_INVENTORY_MAX_NUM];
|
||||
LPITEM pSSCItems[SPECIAL_INVENTORY_MAX_NUM];
|
||||
WORD wSSCItemGrid[SPECIAL_INVENTORY_MAX_NUM];
|
||||
LPITEM pCostumeItems[SPECIAL_INVENTORY_MAX_NUM];
|
||||
WORD wCostumeItemGrid[SPECIAL_INVENTORY_MAX_NUM];
|
||||
#endif
|
||||
} CHARACTER_ITEM_CELLS;
|
||||
|
||||
/* 저장되지 않는 캐릭터 데이터 */
|
||||
typedef struct character_point_instant
|
||||
{
|
||||
@@ -411,28 +477,10 @@ typedef struct character_point_instant
|
||||
|
||||
WORD parts[PART_MAX_NUM];
|
||||
|
||||
LPITEM pItems[INVENTORY_AND_EQUIP_SLOT_MAX];
|
||||
WORD bItemGrid[INVENTORY_AND_EQUIP_SLOT_MAX]; // MT: BYTE in 40250; holds cell + 1, and cells reach 302
|
||||
|
||||
// 용혼석 인벤토리.
|
||||
LPITEM pDSItems[DRAGON_SOUL_INVENTORY_MAX_NUM];
|
||||
WORD wDSItemGrid[DRAGON_SOUL_INVENTORY_MAX_NUM];
|
||||
CHARACTER_ITEM_CELLS* pItemCells; // MT: PCs only (CHARACTER::Create); mobs/NPCs read the shared empty set
|
||||
|
||||
LPITEM pSwitchbotItems[SWITCHBOT_SLOT_COUNT]; // PORT: AVA2 switchbot window (port_switchbot.cpp)
|
||||
|
||||
#ifdef ENABLE_SPECIAL_STORAGE
|
||||
LPITEM pSSUItems[SPECIAL_INVENTORY_MAX_NUM];
|
||||
WORD wSSUItemGrid[SPECIAL_INVENTORY_MAX_NUM];
|
||||
LPITEM pSSBItems[SPECIAL_INVENTORY_MAX_NUM];
|
||||
WORD wSSBItemGrid[SPECIAL_INVENTORY_MAX_NUM];
|
||||
LPITEM pSSSItems[SPECIAL_INVENTORY_MAX_NUM];
|
||||
WORD wSSSItemGrid[SPECIAL_INVENTORY_MAX_NUM];
|
||||
LPITEM pSSCItems[SPECIAL_INVENTORY_MAX_NUM];
|
||||
WORD wSSCItemGrid[SPECIAL_INVENTORY_MAX_NUM];
|
||||
LPITEM pCostumeItems[SPECIAL_INVENTORY_MAX_NUM];
|
||||
WORD wCostumeItemGrid[SPECIAL_INVENTORY_MAX_NUM];
|
||||
#endif
|
||||
|
||||
// by mhh
|
||||
LPITEM pCubeItems[CUBE_MAX_NUM];
|
||||
LPCHARACTER pCubeNpc;
|
||||
@@ -571,6 +619,10 @@ class CHARACTER : public CEntity, public CFSM, public CHorseRider
|
||||
|
||||
public:
|
||||
DWORD m_portFeatureLastQuery = 0; // PORT: read-only query throttle, not persisted.
|
||||
bool m_portQuiverSync = false; // PORT: only this character's negotiated client.
|
||||
void PortEnableQuiverSync();
|
||||
void PortSendQuiverState(LPCHARACTER viewer);
|
||||
void PortBroadcastQuiverState();
|
||||
bool m_portQuietInfo = false; // PORT: batch actions hold back per-item INFO lines...
|
||||
std::string m_portLastInfo; // ...keeping the last one to report a rejected item.
|
||||
DWORD m_portPickupLastCommand = 0; // PORT: batch pickup throttle.
|
||||
@@ -694,6 +746,14 @@ class CHARACTER : public CEntity, public CFSM, public CHorseRider
|
||||
void SetLastShoutPulse(DWORD pulse) { m_pointsInstant.dwLastShoutPulse = pulse; }
|
||||
int GetLevel() const { return m_points.level; }
|
||||
void SetLevel(BYTE level);
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
int GetConquerorLevel() const { return m_points.conquerorlevel; }
|
||||
void SetConquerorLevel(BYTE level) { m_points.conquerorlevel = level; }
|
||||
DWORD GetConquerorExp() const { return m_points.conqueror_exp; }
|
||||
void SetConquerorExp(DWORD exp) { m_points.conqueror_exp = exp; }
|
||||
DWORD GetConquerorNextExp() const;
|
||||
bool IsConquerorMap(long lMapIndex) const;
|
||||
#endif
|
||||
|
||||
BYTE GetGMLevel() const;
|
||||
BOOL IsGM() const;
|
||||
@@ -1124,7 +1184,10 @@ class CHARACTER : public CEntity, public CFSM, public CHorseRider
|
||||
|
||||
void ClearItem();
|
||||
void SetItem(TItemPos Cell, LPITEM item);
|
||||
bool PortCubeInstallImage(const PortCube::InventoryImage&,const std::vector<LPITEM>& before,const std::vector<LPITEM>& restored);
|
||||
bool PortCubePublishFrame(const PortCubeView::Frame&,const PortCubeView::Frame& original);
|
||||
LPITEM GetItem(TItemPos Cell) const;
|
||||
const CHARACTER_ITEM_CELLS& ItemCells() const;
|
||||
LPITEM GetInventoryItem(WORD wCell) const;
|
||||
#ifdef ENABLE_SPECIAL_STORAGE
|
||||
LPITEM GetUpgradeInventoryItem(WORD wCell) const;
|
||||
@@ -1163,7 +1226,7 @@ class CHARACTER : public CEntity, public CFSM, public CHorseRider
|
||||
// END_OF_ADD_REFINE_BUILDING
|
||||
|
||||
bool RefineItem(LPITEM pkItem, LPITEM pkTarget);
|
||||
bool DropItem(TItemPos Cell, BYTE bCount=0);
|
||||
bool DropItem(TItemPos Cell, DWORD bCount=0);
|
||||
bool GiveRecallItem(LPITEM item);
|
||||
void ProcessRecallItem(LPITEM item);
|
||||
|
||||
@@ -1187,7 +1250,7 @@ class CHARACTER : public CEntity, public CFSM, public CHorseRider
|
||||
bool GiveItemFromSpecialItemGroup(DWORD dwGroupNum, std::vector <DWORD> &dwItemVnums,
|
||||
std::vector <DWORD> &dwItemCounts, std::vector <LPITEM> &item_gets, int &count);
|
||||
|
||||
bool MoveItem(TItemPos pos, TItemPos change_pos, BYTE num);
|
||||
bool MoveItem(TItemPos pos, TItemPos change_pos, DWORD num);
|
||||
DWORD GetPickUPMode() { return DWORD(GetQuestFlag("ava2_pickup.mode")); }
|
||||
DWORD GetPickUPRarityMode() { return DWORD(GetQuestFlag("ava2_pickup.rarity")); }
|
||||
void ChangePickUPMode(DWORD mode,DWORD rarity);
|
||||
@@ -1212,8 +1275,8 @@ class CHARACTER : public CEntity, public CFSM, public CHorseRider
|
||||
bool CanUnequipNow(const LPITEM item, const TItemPos& srcCell = NPOS, const TItemPos& destCell = NPOS);
|
||||
|
||||
bool SwapItem(WORD bCell, WORD bDestCell);
|
||||
LPITEM AutoGiveItem(DWORD dwItemVnum, BYTE bCount=1, int iRarePct = -1, bool bMsg = true);
|
||||
void AutoGiveItem(LPITEM item, bool longOwnerShip = false);
|
||||
LPITEM AutoGiveItem(DWORD dwItemVnum, DWORD bCount=1, int iRarePct = -1, bool bMsg = true);
|
||||
LPITEM AutoGiveItem(LPITEM item, bool longOwnerShip = false);
|
||||
|
||||
int GetEmptyInventory(BYTE size) const;
|
||||
int GetEmptyDragonSoulInventory(LPITEM pItem) const;
|
||||
@@ -1281,7 +1344,7 @@ class CHARACTER : public CEntity, public CFSM, public CHorseRider
|
||||
void SetShopOwner(LPCHARACTER ch) { m_pkChrShopOwner = ch; }
|
||||
LPCHARACTER GetShopOwner() const { return m_pkChrShopOwner;}
|
||||
|
||||
void OpenMyShop(const char * c_pszSign, TShopItemTable * pTable, BYTE bItemCount);
|
||||
void OpenMyShop(const char * c_pszSign, TShopItemTable * pTable, BYTE bItemCount, const int32_t * pCheque = NULL);
|
||||
LPSHOP GetMyShop() const { return m_pkMyShop; }
|
||||
void CloseMyShop();
|
||||
|
||||
@@ -1360,6 +1423,10 @@ class CHARACTER : public CEntity, public CFSM, public CHorseRider
|
||||
void AttackedByPoison(LPCHARACTER pkAttacker);
|
||||
void RemovePoison();
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
void AttackedByBleeding(LPCHARACTER pkAttacker);
|
||||
void RemoveBleeding();
|
||||
#endif
|
||||
void AttackedByFire(LPCHARACTER pkAttacker, int amount, int count);
|
||||
void RemoveFire();
|
||||
|
||||
@@ -1481,6 +1548,9 @@ class CHARACTER : public CEntity, public CFSM, public CHorseRider
|
||||
|
||||
void ComputePassiveSkill(DWORD dwVnum);
|
||||
int ComputeSkill(DWORD dwVnum, LPCHARACTER pkVictim, BYTE bSkillLevel = 0);
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
int ComputeSkillParty(DWORD dwVnum, LPCHARACTER pkVictim, BYTE bSkillLevel = 0);
|
||||
#endif
|
||||
int ComputeSkillAtPosition(DWORD dwVnum, const PIXEL_POSITION& posTarget, BYTE bSkillLevel = 0);
|
||||
void ComputeSkillPoints();
|
||||
|
||||
@@ -1516,9 +1586,16 @@ class CHARACTER : public CEntity, public CFSM, public CHorseRider
|
||||
public:
|
||||
void StartMuyeongEvent();
|
||||
void StopMuyeongEvent();
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
void StartCheonunEvent(long lApplyValue);
|
||||
void StopCheonunEvent();
|
||||
#endif
|
||||
|
||||
private:
|
||||
LPEVENT m_pkMuyeongEvent;
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
LPEVENT m_pkCheonunEvent;
|
||||
#endif
|
||||
|
||||
// for SKILL_CHAIN lighting
|
||||
public:
|
||||
@@ -1828,6 +1905,9 @@ class CHARACTER : public CEntity, public CFSM, public CHorseRider
|
||||
LPEVENT m_pkFishingEvent;
|
||||
LPEVENT m_pkAffectEvent;
|
||||
LPEVENT m_pkPoisonEvent;
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
LPEVENT m_pkBleedingEvent;
|
||||
#endif
|
||||
LPEVENT m_pkFireEvent;
|
||||
LPEVENT m_pkWarpNPCEvent;
|
||||
//DELAYED_WARP
|
||||
@@ -1845,6 +1925,9 @@ class CHARACTER : public CEntity, public CFSM, public CHorseRider
|
||||
|
||||
bool m_bHasPoisoned;
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
bool m_bHasBled;
|
||||
#endif
|
||||
const CMob * m_pkMobData;
|
||||
CMobInstance * m_pkMobInst;
|
||||
|
||||
@@ -1989,6 +2072,7 @@ class CHARACTER : public CEntity, public CFSM, public CHorseRider
|
||||
// by mhh
|
||||
LPITEM* GetCubeItem() { return m_pointsInstant.pCubeItems; }
|
||||
bool IsCubeOpen () const { return (m_pointsInstant.pCubeNpc?true:false); }
|
||||
LPCHARACTER GetCubeNpc() const { return m_pointsInstant.pCubeNpc; } // PORT: read-only catalogue context
|
||||
void SetCubeNpc(LPCHARACTER npc) { m_pointsInstant.pCubeNpc = npc; }
|
||||
bool CanDoCube() const;
|
||||
|
||||
|
||||
@@ -475,6 +475,10 @@ void CHARACTER::LoadAffect(DWORD dwCount, TPacketAffectElement * pElements)
|
||||
// 무영진은 로드하지않는다.
|
||||
if (pElements->dwType == SKILL_MUYEONG)
|
||||
continue;
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
if (pElements->dwType == SKILL_CHEONUN)
|
||||
continue;
|
||||
#endif
|
||||
|
||||
if (AFFECT_AUTO_HP_RECOVERY == pElements->dwType || AFFECT_AUTO_SP_RECOVERY == pElements->dwType)
|
||||
{
|
||||
@@ -670,6 +674,16 @@ void CHARACTER::ComputeAffect(CAffect * pkAff, bool bAdd)
|
||||
else
|
||||
StopMuyeongEvent();
|
||||
}
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
|
||||
if (pkAff->dwType == SKILL_CHEONUN)
|
||||
{
|
||||
if (bAdd)
|
||||
StartCheonunEvent(pkAff->lApplyValue);
|
||||
else
|
||||
StopCheonunEvent();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CHARACTER::RemoveAffect(CAffect * pkAff)
|
||||
@@ -766,6 +780,14 @@ void CHARACTER::RemoveGoodAffect()
|
||||
RemoveAffect(SKILL_KWAESOK);
|
||||
RemoveAffect(SKILL_JEUNGRYEOK);
|
||||
RemoveAffect(SKILL_GICHEON);
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
// 수인족(WOLFMEN) 버프 추가
|
||||
RemoveAffect(SKILL_JEOKRANG);
|
||||
RemoveAffect(SKILL_CHEONGRANG);
|
||||
#endif
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
RemoveAffect(SKILL_CHEONUN);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CHARACTER::IsGoodAffect(BYTE bAffectType) const
|
||||
@@ -794,6 +816,14 @@ bool CHARACTER::IsGoodAffect(BYTE bAffectType) const
|
||||
case (SKILL_KWAESOK):
|
||||
case (SKILL_JEUNGRYEOK):
|
||||
case (SKILL_GICHEON):
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
// 수인족(WOLFMEN) 버프 추가
|
||||
case (SKILL_JEOKRANG):
|
||||
case (SKILL_CHEONGRANG):
|
||||
#endif
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
case (SKILL_CHEONUN):
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -804,6 +834,9 @@ void CHARACTER::RemoveBadAffect()
|
||||
sys_log(0, "RemoveBadAffect %s", GetName());
|
||||
// 독
|
||||
RemovePoison();
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
RemoveBleeding();
|
||||
#endif
|
||||
RemoveFire();
|
||||
|
||||
// 스턴 : Value%로 상대방을 5초간 머리 위에 별이 돌아간다. (때리면 1/2 확률로 풀림) AFF_STUN
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "item_manager.h"
|
||||
#include "mob_manager.h"
|
||||
#include "battle.h"
|
||||
#include "sectree_manager.h"
|
||||
#include "pvp.h"
|
||||
#include "skill.h"
|
||||
#include "start_position.h"
|
||||
@@ -46,6 +47,7 @@
|
||||
#include "port_battlepass_hooks.h"
|
||||
#include "ava2_itemshop.h"
|
||||
#include <algorithm>
|
||||
#include "port_quiver.h"
|
||||
DWORD AdjustExpByLevel(const LPCHARACTER ch, const DWORD exp)
|
||||
{
|
||||
if (PLAYER_EXP_TABLE_MAX < ch->GetLevel())
|
||||
@@ -1641,6 +1643,24 @@ void CHARACTER::SendDamagePacket(LPCHARACTER pAttacker, int Damage, BYTE DamageF
|
||||
bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // returns true if dead
|
||||
{
|
||||
if (!CNewMobTimer::instance().CheckDamage(pAttacker,this)) return false;
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
if (IsAffectFlag(AFF_CHUNWOON_MOOJUK))
|
||||
{
|
||||
if (pAttacker)
|
||||
SendDamagePacket(pAttacker, 0, (1 << 3)); // client DAMAGE_BLOCK
|
||||
return false;
|
||||
}
|
||||
|
||||
// conqueror maps: monsters take half damage below the map's sungma_str requirement, none at conqueror level 0
|
||||
if (pAttacker && pAttacker->IsPC() && !IsPC() && pAttacker->IsConquerorMap(pAttacker->GetMapIndex()))
|
||||
{
|
||||
if (pAttacker->GetPoint(POINT_SUNGMA_STR) < SECTREE_MANAGER::instance().GetSungmaValueAffectByRegion(pAttacker->GetMapIndex(), AFFECT_SUNGMA_STR))
|
||||
dam /= 2;
|
||||
|
||||
if (pAttacker->GetConquerorLevel() == 0)
|
||||
dam = 0;
|
||||
}
|
||||
#endif
|
||||
if (DAMAGE_TYPE_MAGIC == type)
|
||||
{
|
||||
dam = (int)((float)dam * (100 + (pAttacker->GetPoint(POINT_MAGIC_ATT_BONUS_PER) + pAttacker->GetPoint(POINT_MELEE_MAGIC_ATT_BONUS_PER))) / 100.f + 0.5f);
|
||||
@@ -1738,7 +1758,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
|
||||
// PORT: AVA2 ENABLE_MELEY_LAIR_DUNGEON. A Meley statue turned to stone (npc.set_protect_time "IsMeleyBlock").
|
||||
if (pAttacker && GetProtectTime("IsMeleyBlock") == 1)
|
||||
{
|
||||
SendDamagePacket(pAttacker, 0, DAMAGE_BLOCK);
|
||||
SendDamagePacket(pAttacker, 0, (1 << 3)); // client DAMAGE_BLOCK
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1853,7 +1873,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%s ºí·°! (%d%%)"), GetName(), GetPoint(POINT_BLOCK));
|
||||
}
|
||||
|
||||
SendDamagePacket(pAttacker, 0, DAMAGE_BLOCK);
|
||||
SendDamagePacket(pAttacker, 0, (1 << 3)); // client DAMAGE_BLOCK
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -2236,6 +2256,15 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
else if (type == DAMAGE_TYPE_BLEEDING)
|
||||
{
|
||||
if (GetHP() - dam <= 0)
|
||||
{
|
||||
dam = GetHP();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// ------------------------
|
||||
// µ¶ÀÏ ÇÁ¸®¹Ì¾ö ¸ðµå
|
||||
// -----------------------
|
||||
@@ -2554,8 +2583,18 @@ static void GiveExp(LPCHARACTER from, LPCHARACTER to, int iExp)
|
||||
pet->PointChange(POINT_PET_EXP, iExp * 5);
|
||||
#endif
|
||||
|
||||
to->PointChange(POINT_EXP, iExp, true);
|
||||
from->CreateFly(FLY_EXP, to);
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
if (to->IsConquerorMap(to->GetMapIndex()))
|
||||
{
|
||||
to->PointChange(POINT_CONQUEROR_EXP, iExp, true);
|
||||
from->CreateFly(FLY_CONQUEROR_EXP, to);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
to->PointChange(POINT_EXP, iExp, true);
|
||||
from->CreateFly(FLY_EXP, to);
|
||||
}
|
||||
|
||||
{
|
||||
LPCHARACTER you = to->GetMarryPartner();
|
||||
@@ -2876,12 +2915,19 @@ int CHARACTER::GetArrowAndBow(LPITEM * ppkBow, LPITEM * ppkArrow, int iArrowCoun
|
||||
LPITEM pkArrow;
|
||||
|
||||
if (!(pkArrow = GetWear(WEAR_ARROW)) || pkArrow->GetType() != ITEM_WEAPON ||
|
||||
pkArrow->GetProto()->bSubType != WEAPON_ARROW)
|
||||
(pkArrow->GetProto()->bSubType != WEAPON_ARROW && pkArrow->GetProto()->bSubType != WEAPON_QUIVER))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
iArrowCount = MIN(iArrowCount, pkArrow->GetCount());
|
||||
if (pkArrow->GetSubType() == WEAPON_QUIVER)
|
||||
{
|
||||
if (!PortQuiverUsable(pkArrow))
|
||||
return 0;
|
||||
iArrowCount = MIN(iArrowCount, 200);
|
||||
}
|
||||
else
|
||||
iArrowCount = MIN(iArrowCount, pkArrow->GetCount());
|
||||
|
||||
*ppkBow = pkBow;
|
||||
*ppkArrow = pkArrow;
|
||||
@@ -2891,6 +2937,9 @@ int CHARACTER::GetArrowAndBow(LPITEM * ppkBow, LPITEM * ppkArrow, int iArrowCoun
|
||||
|
||||
void CHARACTER::UseArrow(LPITEM pkArrow, DWORD dwArrowCount)
|
||||
{
|
||||
if (pkArrow->GetSubType() == WEAPON_QUIVER)
|
||||
return;
|
||||
|
||||
int iCount = pkArrow->GetCount();
|
||||
DWORD dwVnum = pkArrow->GetVnum();
|
||||
iCount = iCount - MIN(iCount, dwArrowCount);
|
||||
@@ -3116,6 +3165,27 @@ class CFuncShoot
|
||||
|
||||
break;
|
||||
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
case SKILL_PUNGLOEPO:
|
||||
{
|
||||
int iUseArrow = 1;
|
||||
if (iUseArrow == m_me->GetArrowAndBow(&pkBow, &pkArrow, iUseArrow))
|
||||
{
|
||||
m_me->OnMove(true);
|
||||
pkVictim->OnMove();
|
||||
|
||||
if (pkVictim->CanBeginFight())
|
||||
pkVictim->BeginFight(m_me);
|
||||
|
||||
sys_log(0, "%s pungloepo %s", m_me->GetName(), pkVictim->GetName());
|
||||
m_me->ComputeSkill(m_bType, pkVictim);
|
||||
m_me->UseArrow(pkArrow, iUseArrow);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
#endif
|
||||
|
||||
case SKILL_HORSE_WILDATTACK_RANGE:
|
||||
{
|
||||
int iUseArrow = 1;
|
||||
@@ -3144,6 +3214,11 @@ class CFuncShoot
|
||||
case SKILL_SANGONG:
|
||||
case SKILL_MAHWAN:
|
||||
case SKILL_PABEOB:
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
case SKILL_ILGWANGPYO:
|
||||
case SKILL_MABEOBAGGWI:
|
||||
case SKILL_METEO:
|
||||
#endif
|
||||
//case SKILL_CURSE:
|
||||
{
|
||||
m_me->OnMove(true);
|
||||
|
||||
@@ -23,14 +23,19 @@ int CHARACTER::ChangeEmpire(BYTE empire)
|
||||
|
||||
char szQuery[1024+1];
|
||||
DWORD dwAID;
|
||||
DWORD dwPID[4];
|
||||
DWORD dwPID[PLAYER_PER_ACCOUNT];
|
||||
memset(dwPID, 0, sizeof(dwPID));
|
||||
|
||||
{
|
||||
// 1. 내 계정의 모든 pid를 얻어 온다
|
||||
snprintf(szQuery, sizeof(szQuery),
|
||||
#ifdef ENABLE_PLAYER_PER_ACCOUNT5
|
||||
"SELECT id, pid1, pid2, pid3, pid4, pid5 FROM player_index%s WHERE pid1=%u OR pid2=%u OR pid3=%u OR pid4=%u OR pid5=%u AND empire=%u",
|
||||
get_table_postfix(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetEmpire());
|
||||
#else
|
||||
"SELECT id, pid1, pid2, pid3, pid4 FROM player_index%s WHERE pid1=%u OR pid2=%u OR pid3=%u OR pid4=%u AND empire=%u",
|
||||
get_table_postfix(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetEmpire());
|
||||
#endif
|
||||
|
||||
std::unique_ptr<SQLMsg> msg(DBManager::instance().DirectQuery(szQuery));
|
||||
|
||||
@@ -42,19 +47,18 @@ int CHARACTER::ChangeEmpire(BYTE empire)
|
||||
MYSQL_ROW row = mysql_fetch_row(msg->Get()->pSQLResult);
|
||||
|
||||
str_to_number(dwAID, row[0]);
|
||||
str_to_number(dwPID[0], row[1]);
|
||||
str_to_number(dwPID[1], row[2]);
|
||||
str_to_number(dwPID[2], row[3]);
|
||||
str_to_number(dwPID[3], row[4]);
|
||||
for (int i = 0; i < PLAYER_PER_ACCOUNT; ++i)
|
||||
str_to_number(dwPID[i], row[i + 1]);
|
||||
}
|
||||
|
||||
const int loop = 4;
|
||||
// PORT: AVA2 kept 4 here, skipping the fifth character's guild/marriage check.
|
||||
const int loop = PLAYER_PER_ACCOUNT;
|
||||
|
||||
{
|
||||
// 2. 각 캐릭터의 길드 정보를 얻어온다.
|
||||
// 한 캐릭터라도 길드에 가입 되어 있다면, 제국 이동을 할 수 없다.
|
||||
DWORD dwGuildID[4];
|
||||
CGuild * pGuild[4];
|
||||
DWORD dwGuildID[PLAYER_PER_ACCOUNT];
|
||||
CGuild * pGuild[PLAYER_PER_ACCOUNT];
|
||||
SQLMsg * pMsg = NULL;
|
||||
|
||||
for (int i = 0; i < loop; ++i)
|
||||
@@ -102,8 +106,13 @@ int CHARACTER::ChangeEmpire(BYTE empire)
|
||||
|
||||
{
|
||||
// 4. db의 제국 정보를 업데이트 한다.
|
||||
#ifdef ENABLE_PLAYER_PER_ACCOUNT5
|
||||
snprintf(szQuery, sizeof(szQuery), "UPDATE player_index%s SET empire=%u WHERE pid1=%u OR pid2=%u OR pid3=%u OR pid4=%u OR pid5=%u AND empire=%u",
|
||||
get_table_postfix(), empire, GetPlayerID(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetEmpire());
|
||||
#else
|
||||
snprintf(szQuery, sizeof(szQuery), "UPDATE player_index%s SET empire=%u WHERE pid1=%u OR pid2=%u OR pid3=%u OR pid4=%u AND empire=%u",
|
||||
get_table_postfix(), empire, GetPlayerID(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetEmpire());
|
||||
#endif
|
||||
|
||||
std::unique_ptr<SQLMsg> msg(DBManager::instance().DirectQuery(szQuery));
|
||||
|
||||
@@ -181,8 +190,13 @@ DWORD CHARACTER::GetAID() const
|
||||
char szQuery[1024+1];
|
||||
DWORD dwAID = 0;
|
||||
|
||||
#ifdef ENABLE_PLAYER_PER_ACCOUNT5
|
||||
snprintf(szQuery, sizeof(szQuery), "SELECT id FROM player_index%s WHERE pid1=%u OR pid2=%u OR pid3=%u OR pid4=%u OR pid5=%u AND empire=%u",
|
||||
get_table_postfix(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetEmpire());
|
||||
#else
|
||||
snprintf(szQuery, sizeof(szQuery), "SELECT id FROM player_index%s WHERE pid1=%u OR pid2=%u OR pid3=%u OR pid4=%u AND empire=%u",
|
||||
get_table_postfix(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetEmpire());
|
||||
#endif
|
||||
|
||||
SQLMsg* pMsg = DBManager::instance().DirectQuery(szQuery);
|
||||
|
||||
|
||||
+252
-259
@@ -1,6 +1,10 @@
|
||||
#include "stdafx.h"
|
||||
#include "port_material_stack_policy.h"
|
||||
#include "port_cube_actor.h"
|
||||
#include "../../common/gold_bounds.h"
|
||||
|
||||
// Pickup locale keys must stay CP949, matching locale_string.txt on the server.
|
||||
// UTF-8 source literals miss the dictionary and emit a corrupt @0949 fallback.
|
||||
#include <stack>
|
||||
|
||||
#include "utils.h"
|
||||
@@ -56,6 +60,7 @@
|
||||
#include "port_premium.h"
|
||||
#include "port_battlepass_hooks.h"
|
||||
#include "PetSystem.h"
|
||||
#include "port_refine_materials.h"
|
||||
const int ITEM_BROKEN_METIN_VNUM = 28960;
|
||||
|
||||
// CHANGE_ITEM_ATTRIBUTES
|
||||
@@ -216,6 +221,7 @@ static bool FN_check_item_sex(LPCHARACTER ch, LPITEM item)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
bool CHARACTER::CanHandleItem(bool bSkipCheckRefine, bool bSkipObserver)
|
||||
{
|
||||
if(PortCubeActorHeld(this))return false;
|
||||
if (!bSkipObserver)
|
||||
if (m_bIsObserver)
|
||||
return false;
|
||||
@@ -265,6 +271,12 @@ LPITEM CHARACTER::GetCostumeInventoryItem(WORD wCell) const
|
||||
return GetItem(TItemPos(COSTUME_INVENTORY, wCell));
|
||||
}
|
||||
#endif
|
||||
const CHARACTER_ITEM_CELLS& CHARACTER::ItemCells() const
|
||||
{
|
||||
static const CHARACTER_ITEM_CELLS s_empty = {};
|
||||
return m_pointsInstant.pItemCells ? *m_pointsInstant.pItemCells : s_empty;
|
||||
}
|
||||
|
||||
LPITEM CHARACTER::GetItem(TItemPos Cell) const
|
||||
{
|
||||
if (!IsValidItemPosition(Cell))
|
||||
@@ -280,14 +292,14 @@ LPITEM CHARACTER::GetItem(TItemPos Cell) const
|
||||
sys_err("CHARACTER::GetInventoryItem: invalid item cell %d", wCell);
|
||||
return NULL;
|
||||
}
|
||||
return m_pointsInstant.pItems[wCell];
|
||||
return ItemCells().pItems[wCell];
|
||||
case DRAGON_SOUL_INVENTORY:
|
||||
if (wCell >= DRAGON_SOUL_INVENTORY_MAX_NUM)
|
||||
{
|
||||
sys_err("CHARACTER::GetInventoryItem: invalid DS item cell %d", wCell);
|
||||
return NULL;
|
||||
}
|
||||
return m_pointsInstant.pDSItems[wCell];
|
||||
return ItemCells().pDSItems[wCell];
|
||||
// PORT: AVA2 ENABLE_SWITCHBOT window (port_switchbot.cpp).
|
||||
case SWITCHBOT:
|
||||
if (wCell >= SWITCHBOT_SLOT_COUNT)
|
||||
@@ -304,35 +316,35 @@ LPITEM CHARACTER::GetItem(TItemPos Cell) const
|
||||
sys_err("CHARACTER::GetInventoryItem: invalid SSU item cell %d", wCell);
|
||||
return NULL;
|
||||
}
|
||||
return m_pointsInstant.pSSUItems[wCell];
|
||||
return ItemCells().pSSUItems[wCell];
|
||||
case BOOK_INVENTORY:
|
||||
if (wCell >= SPECIAL_INVENTORY_MAX_NUM)
|
||||
{
|
||||
sys_err("CHARACTER::GetInventoryItem: invalid SSB item cell %d", wCell);
|
||||
return NULL;
|
||||
}
|
||||
return m_pointsInstant.pSSBItems[wCell];
|
||||
return ItemCells().pSSBItems[wCell];
|
||||
case STONE_INVENTORY:
|
||||
if (wCell >= SPECIAL_INVENTORY_MAX_NUM)
|
||||
{
|
||||
sys_err("CHARACTER::GetInventoryItem: invalid SSS item cell %d", wCell);
|
||||
return NULL;
|
||||
}
|
||||
return m_pointsInstant.pSSSItems[wCell];
|
||||
return ItemCells().pSSSItems[wCell];
|
||||
case CHANGE_INVENTORY:
|
||||
if (wCell >= SPECIAL_INVENTORY_MAX_NUM)
|
||||
{
|
||||
sys_err("CHARACTER::GetInventoryItem: invalid SSC item cell %d", wCell);
|
||||
return NULL;
|
||||
}
|
||||
return m_pointsInstant.pSSCItems[wCell];
|
||||
return ItemCells().pSSCItems[wCell];
|
||||
case COSTUME_INVENTORY:
|
||||
if (wCell >= SPECIAL_INVENTORY_MAX_NUM)
|
||||
{
|
||||
sys_err("CHARACTER::GetInventoryItem: invalid Costume item cell %d", wCell);
|
||||
return NULL;
|
||||
}
|
||||
return m_pointsInstant.pCostumeItems[wCell];
|
||||
return ItemCells().pCostumeItems[wCell];
|
||||
#endif
|
||||
|
||||
default:
|
||||
@@ -357,6 +369,13 @@ void CHARACTER::SetItem(TItemPos Cell, LPITEM pItem)
|
||||
assert(!"GetOwner exist");
|
||||
return;
|
||||
}
|
||||
CHARACTER_ITEM_CELLS* cells = m_pointsInstant.pItemCells;
|
||||
if (!cells && window_type != SWITCHBOT)
|
||||
{
|
||||
if (pItem)
|
||||
sys_err("CHARACTER::SetItem: %s is not a PC (window %u cell %u)", GetName(), window_type, wCell);
|
||||
return;
|
||||
}
|
||||
// 기본 인벤토리
|
||||
switch(window_type)
|
||||
{
|
||||
@@ -369,7 +388,7 @@ void CHARACTER::SetItem(TItemPos Cell, LPITEM pItem)
|
||||
return;
|
||||
}
|
||||
|
||||
LPITEM pOld = m_pointsInstant.pItems[wCell];
|
||||
LPITEM pOld = cells->pItems[wCell];
|
||||
|
||||
if (pOld)
|
||||
{
|
||||
@@ -382,14 +401,14 @@ void CHARACTER::SetItem(TItemPos Cell, LPITEM pItem)
|
||||
if (p >= INVENTORY_MAX_NUM)
|
||||
continue;
|
||||
|
||||
if (m_pointsInstant.pItems[p] && m_pointsInstant.pItems[p] != pOld)
|
||||
if (cells->pItems[p] && cells->pItems[p] != pOld)
|
||||
continue;
|
||||
|
||||
m_pointsInstant.bItemGrid[p] = 0;
|
||||
cells->bItemGrid[p] = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
m_pointsInstant.bItemGrid[wCell] = 0;
|
||||
cells->bItemGrid[wCell] = 0;
|
||||
}
|
||||
|
||||
if (pItem)
|
||||
@@ -405,20 +424,20 @@ void CHARACTER::SetItem(TItemPos Cell, LPITEM pItem)
|
||||
|
||||
// wCell + 1 로 하는 것은 빈곳을 체크할 때 같은
|
||||
// 아이템은 예외처리하기 위함
|
||||
m_pointsInstant.bItemGrid[p] = wCell + 1;
|
||||
cells->bItemGrid[p] = wCell + 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
m_pointsInstant.bItemGrid[wCell] = wCell + 1;
|
||||
cells->bItemGrid[wCell] = wCell + 1;
|
||||
}
|
||||
|
||||
m_pointsInstant.pItems[wCell] = pItem;
|
||||
cells->pItems[wCell] = pItem;
|
||||
}
|
||||
break;
|
||||
// 용혼석 인벤토리
|
||||
case DRAGON_SOUL_INVENTORY:
|
||||
{
|
||||
LPITEM pOld = m_pointsInstant.pDSItems[wCell];
|
||||
LPITEM pOld = cells->pDSItems[wCell];
|
||||
|
||||
if (pOld)
|
||||
{
|
||||
@@ -431,14 +450,14 @@ void CHARACTER::SetItem(TItemPos Cell, LPITEM pItem)
|
||||
if (p >= DRAGON_SOUL_INVENTORY_MAX_NUM)
|
||||
continue;
|
||||
|
||||
if (m_pointsInstant.pDSItems[p] && m_pointsInstant.pDSItems[p] != pOld)
|
||||
if (cells->pDSItems[p] && cells->pDSItems[p] != pOld)
|
||||
continue;
|
||||
|
||||
m_pointsInstant.wDSItemGrid[p] = 0;
|
||||
cells->wDSItemGrid[p] = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
m_pointsInstant.wDSItemGrid[wCell] = 0;
|
||||
cells->wDSItemGrid[wCell] = 0;
|
||||
}
|
||||
|
||||
if (pItem)
|
||||
@@ -460,14 +479,14 @@ void CHARACTER::SetItem(TItemPos Cell, LPITEM pItem)
|
||||
|
||||
// wCell + 1 로 하는 것은 빈곳을 체크할 때 같은
|
||||
// 아이템은 예외처리하기 위함
|
||||
m_pointsInstant.wDSItemGrid[p] = wCell + 1;
|
||||
cells->wDSItemGrid[p] = wCell + 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
m_pointsInstant.wDSItemGrid[wCell] = wCell + 1;
|
||||
cells->wDSItemGrid[wCell] = wCell + 1;
|
||||
}
|
||||
|
||||
m_pointsInstant.pDSItems[wCell] = pItem;
|
||||
cells->pDSItems[wCell] = pItem;
|
||||
}
|
||||
break;
|
||||
case SWITCHBOT:
|
||||
@@ -509,17 +528,17 @@ void CHARACTER::SetItem(TItemPos Cell, LPITEM pItem)
|
||||
return;
|
||||
}
|
||||
|
||||
LPITEM* pItemArray = (window_type == UPGRADE_INVENTORY) ? m_pointsInstant.pSSUItems :
|
||||
(window_type == BOOK_INVENTORY) ? m_pointsInstant.pSSBItems :
|
||||
(window_type == STONE_INVENTORY) ? m_pointsInstant.pSSSItems :
|
||||
(window_type == CHANGE_INVENTORY) ? m_pointsInstant.pSSCItems :
|
||||
m_pointsInstant.pCostumeItems;
|
||||
LPITEM* pItemArray = (window_type == UPGRADE_INVENTORY) ? cells->pSSUItems :
|
||||
(window_type == BOOK_INVENTORY) ? cells->pSSBItems :
|
||||
(window_type == STONE_INVENTORY) ? cells->pSSSItems :
|
||||
(window_type == CHANGE_INVENTORY) ? cells->pSSCItems :
|
||||
cells->pCostumeItems;
|
||||
|
||||
WORD* pGridArray = (window_type == UPGRADE_INVENTORY) ? m_pointsInstant.wSSUItemGrid :
|
||||
(window_type == BOOK_INVENTORY) ? m_pointsInstant.wSSBItemGrid :
|
||||
(window_type == STONE_INVENTORY) ? m_pointsInstant.wSSSItemGrid :
|
||||
(window_type == CHANGE_INVENTORY) ? m_pointsInstant.wSSCItemGrid :
|
||||
m_pointsInstant.wCostumeItemGrid;
|
||||
WORD* pGridArray = (window_type == UPGRADE_INVENTORY) ? cells->wSSUItemGrid :
|
||||
(window_type == BOOK_INVENTORY) ? cells->wSSBItemGrid :
|
||||
(window_type == STONE_INVENTORY) ? cells->wSSSItemGrid :
|
||||
(window_type == CHANGE_INVENTORY) ? cells->wSSCItemGrid :
|
||||
cells->wCostumeItemGrid;
|
||||
|
||||
LPITEM pOld = pItemArray[wCell];
|
||||
if (pOld)
|
||||
@@ -632,7 +651,7 @@ LPITEM CHARACTER::GetWear(BYTE bCell) const
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return m_pointsInstant.pItems[INVENTORY_MAX_NUM + bCell];
|
||||
return ItemCells().pItems[INVENTORY_MAX_NUM + bCell];
|
||||
}
|
||||
|
||||
void CHARACTER::SetWear(BYTE bCell, LPITEM item)
|
||||
@@ -697,6 +716,23 @@ void CHARACTER::ClearItem()
|
||||
M2_DESTROY_ITEM(item);
|
||||
}
|
||||
}
|
||||
#ifdef ENABLE_SPECIAL_STORAGE
|
||||
// PORT: special storage items outlived logout (dangling owner, ITEM_ID_DUP on the next login)
|
||||
for (BYTE window = UPGRADE_INVENTORY; window <= COSTUME_INVENTORY; ++window)
|
||||
{
|
||||
for (i = 0; i < SPECIAL_INVENTORY_MAX_NUM; ++i)
|
||||
{
|
||||
if ((item = GetItem(TItemPos(window, i))))
|
||||
{
|
||||
item->SetSkipSave(true);
|
||||
ITEM_MANAGER::instance().FlushDelayedSave(item);
|
||||
|
||||
item->RemoveFromCharacter();
|
||||
M2_DESTROY_ITEM(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CHARACTER::IsEmptyItemGrid(TItemPos Cell, BYTE bSize, int iExceptionCell) const
|
||||
@@ -721,9 +757,9 @@ bool CHARACTER::IsEmptyItemGrid(TItemPos Cell, BYTE bSize, int iExceptionCell) c
|
||||
if (false == CBeltInventoryHelper::IsAvailableCell(bCell - BELT_INVENTORY_SLOT_START, beltItem->GetValue(0)))
|
||||
return false;
|
||||
|
||||
if (m_pointsInstant.bItemGrid[bCell])
|
||||
if (ItemCells().bItemGrid[bCell])
|
||||
{
|
||||
if (m_pointsInstant.bItemGrid[bCell] == iExceptionCell)
|
||||
if (ItemCells().bItemGrid[bCell] == iExceptionCell)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@@ -736,9 +772,9 @@ bool CHARACTER::IsEmptyItemGrid(TItemPos Cell, BYTE bSize, int iExceptionCell) c
|
||||
else if (bCell >= INVENTORY_MAX_NUM)
|
||||
return false;
|
||||
|
||||
if (m_pointsInstant.bItemGrid[bCell])
|
||||
if (ItemCells().bItemGrid[bCell])
|
||||
{
|
||||
if (m_pointsInstant.bItemGrid[bCell] == iExceptionCell)
|
||||
if (ItemCells().bItemGrid[bCell] == iExceptionCell)
|
||||
{
|
||||
if (bSize == 1)
|
||||
return true;
|
||||
@@ -756,8 +792,8 @@ bool CHARACTER::IsEmptyItemGrid(TItemPos Cell, BYTE bSize, int iExceptionCell) c
|
||||
if (p / INVENTORY_PAGE_SIZE != bPage)
|
||||
return false;
|
||||
|
||||
if (m_pointsInstant.bItemGrid[p])
|
||||
if (m_pointsInstant.bItemGrid[p] != iExceptionCell)
|
||||
if (ItemCells().bItemGrid[p])
|
||||
if (ItemCells().bItemGrid[p] != iExceptionCell)
|
||||
return false;
|
||||
}
|
||||
while (++j < bSize);
|
||||
@@ -786,8 +822,8 @@ bool CHARACTER::IsEmptyItemGrid(TItemPos Cell, BYTE bSize, int iExceptionCell) c
|
||||
if (p / INVENTORY_PAGE_SIZE != bPage)
|
||||
return false;
|
||||
|
||||
if (m_pointsInstant.bItemGrid[p])
|
||||
if (m_pointsInstant.bItemGrid[p] != iExceptionCell)
|
||||
if (ItemCells().bItemGrid[p])
|
||||
if (ItemCells().bItemGrid[p] != iExceptionCell)
|
||||
return false;
|
||||
}
|
||||
while (++j < bSize);
|
||||
@@ -806,9 +842,9 @@ bool CHARACTER::IsEmptyItemGrid(TItemPos Cell, BYTE bSize, int iExceptionCell) c
|
||||
// 따라서 iExceptionCell에 1을 더해 비교한다.
|
||||
iExceptionCell++;
|
||||
|
||||
if (m_pointsInstant.wDSItemGrid[wCell])
|
||||
if (ItemCells().wDSItemGrid[wCell])
|
||||
{
|
||||
if (m_pointsInstant.wDSItemGrid[wCell] == iExceptionCell)
|
||||
if (ItemCells().wDSItemGrid[wCell] == iExceptionCell)
|
||||
{
|
||||
if (bSize == 1)
|
||||
return true;
|
||||
@@ -822,8 +858,8 @@ bool CHARACTER::IsEmptyItemGrid(TItemPos Cell, BYTE bSize, int iExceptionCell) c
|
||||
if (p >= DRAGON_SOUL_INVENTORY_MAX_NUM)
|
||||
return false;
|
||||
|
||||
if (m_pointsInstant.wDSItemGrid[p])
|
||||
if (m_pointsInstant.wDSItemGrid[p] != iExceptionCell)
|
||||
if (ItemCells().wDSItemGrid[p])
|
||||
if (ItemCells().wDSItemGrid[p] != iExceptionCell)
|
||||
return false;
|
||||
}
|
||||
while (++j < bSize);
|
||||
@@ -848,8 +884,8 @@ bool CHARACTER::IsEmptyItemGrid(TItemPos Cell, BYTE bSize, int iExceptionCell) c
|
||||
if (p >= DRAGON_SOUL_INVENTORY_MAX_NUM)
|
||||
return false;
|
||||
|
||||
if (m_pointsInstant.bItemGrid[p])
|
||||
if (m_pointsInstant.wDSItemGrid[p] != iExceptionCell)
|
||||
if (ItemCells().bItemGrid[p])
|
||||
if (ItemCells().wDSItemGrid[p] != iExceptionCell)
|
||||
return false;
|
||||
}
|
||||
while (++j < bSize);
|
||||
@@ -897,11 +933,11 @@ bool CHARACTER::IsEmptyItemGrid(TItemPos Cell, BYTE bSize, int iExceptionCell) c
|
||||
if (bSize == 3 && wCell + 10 >= SPECIAL_INVENTORY_MAX_NUM)
|
||||
return false;
|
||||
#endif
|
||||
const WORD* pGrid = (Cell.window_type == UPGRADE_INVENTORY) ? m_pointsInstant.wSSUItemGrid :
|
||||
(Cell.window_type == BOOK_INVENTORY) ? m_pointsInstant.wSSBItemGrid :
|
||||
(Cell.window_type == STONE_INVENTORY) ? m_pointsInstant.wSSSItemGrid :
|
||||
(Cell.window_type == CHANGE_INVENTORY) ? m_pointsInstant.wSSCItemGrid :
|
||||
m_pointsInstant.wCostumeItemGrid;
|
||||
const WORD* pGrid = (Cell.window_type == UPGRADE_INVENTORY) ? ItemCells().wSSUItemGrid :
|
||||
(Cell.window_type == BOOK_INVENTORY) ? ItemCells().wSSBItemGrid :
|
||||
(Cell.window_type == STONE_INVENTORY) ? ItemCells().wSSSItemGrid :
|
||||
(Cell.window_type == CHANGE_INVENTORY) ? ItemCells().wSSCItemGrid :
|
||||
ItemCells().wCostumeItemGrid;
|
||||
|
||||
iExceptionCell++;
|
||||
|
||||
@@ -994,7 +1030,7 @@ void CHARACTER::CopyDragonSoulItemGrid(std::vector<WORD>& vDragonSoulItemGrid) c
|
||||
{
|
||||
vDragonSoulItemGrid.resize(DRAGON_SOUL_INVENTORY_MAX_NUM);
|
||||
|
||||
std::copy(m_pointsInstant.wDSItemGrid, m_pointsInstant.wDSItemGrid + DRAGON_SOUL_INVENTORY_MAX_NUM, vDragonSoulItemGrid.begin());
|
||||
std::copy(ItemCells().wDSItemGrid, ItemCells().wDSItemGrid + DRAGON_SOUL_INVENTORY_MAX_NUM, vDragonSoulItemGrid.begin());
|
||||
}
|
||||
|
||||
#ifdef ENABLE_SPECIAL_STORAGE
|
||||
@@ -1266,23 +1302,10 @@ bool CHARACTER::DoRefine(LPITEM item, bool bMoneyOnly)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bMoneyOnly && !RefineChance)
|
||||
if (!bMoneyOnly && !RefineChance && !PortRefineTakeMaterials(this,prt))
|
||||
{
|
||||
for (int i = 0; i < prt->material_count; ++i)
|
||||
{
|
||||
if (CountSpecifyItem(prt->materials[i].vnum) < prt->materials[i].count)
|
||||
{
|
||||
if (test_server)
|
||||
{
|
||||
ChatPacket(CHAT_TYPE_INFO, "Find %d, count %d, require %d", prt->materials[i].vnum, CountSpecifyItem(prt->materials[i].vnum), prt->materials[i].count);
|
||||
}
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("개량을 하기 위한 재료가 부족합니다."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < prt->material_count; ++i)
|
||||
RemoveSpecifyItem(prt->materials[i].vnum, prt->materials[i].count);
|
||||
return false;
|
||||
}
|
||||
|
||||
int prob = number(1, 100);
|
||||
@@ -1471,22 +1494,12 @@ bool CHARACTER::DoRefineWithScroll(LPITEM item)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < prt->material_count; ++i)
|
||||
if (!PortRefineTakeMaterials(this,prt))
|
||||
{
|
||||
if (CountSpecifyItem(prt->materials[i].vnum) < prt->materials[i].count)
|
||||
{
|
||||
if (test_server)
|
||||
{
|
||||
ChatPacket(CHAT_TYPE_INFO, "Find %d, count %d, require %d", prt->materials[i].vnum, CountSpecifyItem(prt->materials[i].vnum), prt->materials[i].count);
|
||||
}
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("개량을 하기 위한 재료가 부족합니다."));
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < prt->material_count; ++i)
|
||||
RemoveSpecifyItem(prt->materials[i].vnum, prt->materials[i].count);
|
||||
|
||||
int prob = number(1, 100);
|
||||
int success_prob = prt->prob;
|
||||
bool bDestroyWhenFail = false;
|
||||
@@ -2767,6 +2780,11 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
|
||||
case CSpecialItemGroup::POISON:
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상자에서 나온 녹색 연기를 들이마시자 독이 온몸으로 퍼집니다!"));
|
||||
break;
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case CSpecialItemGroup::BLEEDING:
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상자에서 나온 녹색 연기를 들이마시자 독이 온몸으로 퍼집니다!"));
|
||||
break;
|
||||
#endif
|
||||
case CSpecialItemGroup::MOB_GROUP:
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상자에서 몬스터가 나타났습니다!"));
|
||||
break;
|
||||
@@ -2848,6 +2866,11 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
|
||||
case CSpecialItemGroup::POISON:
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상자에서 나온 녹색 연기를 들이마시자 독이 온몸으로 퍼집니다!"));
|
||||
break;
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case CSpecialItemGroup::BLEEDING:
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상자에서 나온 녹색 연기를 들이마시자 독이 온몸으로 퍼집니다!"));
|
||||
break;
|
||||
#endif
|
||||
case CSpecialItemGroup::MOB_GROUP:
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상자에서 몬스터가 나타났습니다!"));
|
||||
break;
|
||||
@@ -4492,6 +4515,11 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
|
||||
case CSpecialItemGroup::POISON:
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상자에서 나온 녹색 연기를 들이마시자 독이 온몸으로 퍼집니다!"));
|
||||
break;
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case CSpecialItemGroup::BLEEDING:
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상자에서 나온 녹색 연기를 들이마시자 독이 온몸으로 퍼집니다!"));
|
||||
break;
|
||||
#endif
|
||||
|
||||
case CSpecialItemGroup::MOB_GROUP:
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상자에서 몬스터가 나타났습니다!"));
|
||||
@@ -6246,9 +6274,9 @@ bool CHARACTER::UseItem(TItemPos Cell, TItemPos DestCell)
|
||||
return UseItemEx(item, DestCell);
|
||||
}
|
||||
|
||||
bool CHARACTER::DropItem(TItemPos Cell, BYTE bCount)
|
||||
bool CHARACTER::DropItem(TItemPos Cell, DWORD bCount)
|
||||
{
|
||||
LPITEM item = NULL;
|
||||
LPITEM item = NULL;
|
||||
|
||||
if (!CanHandleItem())
|
||||
{
|
||||
@@ -6281,8 +6309,23 @@ bool CHARACTER::DropItem(TItemPos Cell, BYTE bCount)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bCount == 0 || bCount > item->GetCount())
|
||||
bCount = item->GetCount();
|
||||
if (bCount > item->GetCount()) return false;
|
||||
if (bCount == 0) bCount = item->GetCount();
|
||||
|
||||
// Clear the variable, it looks the player does not dropped any item in the past second.
|
||||
if (thecore_pulse() > LastDropTime + 25)
|
||||
CountDrops = 0;
|
||||
|
||||
// It looks the player dropped min. 4 items in the past 1 second
|
||||
if (thecore_pulse() < LastDropTime + 25 && CountDrops >= 4)
|
||||
{
|
||||
// Set it to 0
|
||||
CountDrops = 0;
|
||||
sys_err("%s[%d] has been disconnected because of drophack using", GetName(), GetPlayerID());
|
||||
// Disconnect the player
|
||||
GetDesc()->SetPhase(PHASE_CLOSE);
|
||||
return false;
|
||||
}
|
||||
|
||||
SyncQuickslot(QUICKSLOT_TYPE_ITEM, Cell.cell, 255); // Quickslot 에서 지움
|
||||
|
||||
@@ -6301,19 +6344,17 @@ bool CHARACTER::DropItem(TItemPos Cell, BYTE bCount)
|
||||
sys_log(0, "[DROP_ITEM] drop item count == 0");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// check non-split items for china
|
||||
//if (LC_IsNewCIBN())
|
||||
// if (item->GetVnum() == 71095 || item->GetVnum() == 71050 || item->GetVnum() == 70038)
|
||||
// return false;
|
||||
|
||||
item->SetCount(item->GetCount() - bCount);
|
||||
ITEM_MANAGER::instance().FlushDelayedSave(item);
|
||||
|
||||
pkItemToDrop = ITEM_MANAGER::instance().CreateItem(item->GetVnum(), bCount);
|
||||
|
||||
// copy item socket -- by mhh
|
||||
FN_copy_item_socket(pkItemToDrop, item);
|
||||
pkItemToDrop = ITEM_MANAGER::instance().CreateItem(item->GetOriginalVnum(), bCount);
|
||||
if (!pkItemToDrop) return false;
|
||||
if (!item->CopyStackStateTo(pkItemToDrop)) { M2_DESTROY_ITEM(pkItemToDrop); return false; }
|
||||
if (!item->SetCount(item->GetCount() - bCount)) { M2_DESTROY_ITEM(pkItemToDrop); return false; }
|
||||
ITEM_MANAGER::instance().FlushDelayedSave(item);
|
||||
|
||||
char szBuf[51 + 1];
|
||||
snprintf(szBuf, sizeof(szBuf), "%u %u", pkItemToDrop->GetID(), pkItemToDrop->GetCount());
|
||||
@@ -6321,21 +6362,7 @@ bool CHARACTER::DropItem(TItemPos Cell, BYTE bCount)
|
||||
}
|
||||
|
||||
PIXEL_POSITION pxPos = GetXYZ();
|
||||
|
||||
// Clear the variable, it looks the player does not dropped any item in the past second.
|
||||
if (thecore_pulse() > LastDropTime + 25)
|
||||
CountDrops = 0;
|
||||
|
||||
// It looks the player dropped min. 4 items in the past 1 second
|
||||
if (thecore_pulse() < LastDropTime + 25 && CountDrops >= 4)
|
||||
{
|
||||
// Set it to 0
|
||||
CountDrops = 0;
|
||||
sys_err("%s[%d] has been disconnected because of drophack using", GetName(), GetPlayerID());
|
||||
// Disconnect the player
|
||||
GetDesc()->SetPhase(PHASE_CLOSE);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (pkItemToDrop->AddToGround(GetMapIndex(), pxPos))
|
||||
{
|
||||
@@ -6348,17 +6375,26 @@ bool CHARACTER::DropItem(TItemPos Cell, BYTE bCount)
|
||||
pkItemToDrop->StartDestroyEvent();
|
||||
|
||||
ITEM_MANAGER::instance().FlushDelayedSave(pkItemToDrop);
|
||||
|
||||
|
||||
char szHint[32 + 1];
|
||||
snprintf(szHint, sizeof(szHint), "%s %u %u", pkItemToDrop->GetName(), pkItemToDrop->GetCount(), pkItemToDrop->GetOriginalVnum());
|
||||
LogManager::instance().ItemLog(this, pkItemToDrop, "DROP", szHint);
|
||||
|
||||
|
||||
LastDropTime = thecore_pulse();
|
||||
CountDrops++;
|
||||
|
||||
|
||||
//Motion(MOTION_PICKUP);
|
||||
}
|
||||
|
||||
else {
|
||||
if (pkItemToDrop == item) item->AddToCharacter(this, Cell);
|
||||
else {
|
||||
item->SetCount(item->GetCount() + pkItemToDrop->GetCount());
|
||||
M2_DESTROY_ITEM(pkItemToDrop);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6427,7 +6463,7 @@ bool CHARACTER::DropGold(int64_t gold)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CHARACTER::MoveItem(TItemPos Cell, TItemPos DestCell, BYTE count)
|
||||
bool CHARACTER::MoveItem(TItemPos Cell, TItemPos DestCell, DWORD count)
|
||||
{
|
||||
if (Cell.IsSamePosition(DestCell)) // ItemMove dupe exploit fix
|
||||
return false;
|
||||
@@ -6576,7 +6612,7 @@ bool CHARACTER::MoveItem(TItemPos Cell, TItemPos DestCell, BYTE count)
|
||||
|
||||
if ((item2 = GetItem(DestCell)) && item != item2 && item2->IsStackable() &&
|
||||
!IS_SET(item2->GetAntiFlag(), ITEM_ANTIFLAG_STACK) &&
|
||||
item2->GetVnum() == item->GetVnum()) // 합칠 수 있는 아이템의 경우
|
||||
item2->CanStackWith(item)) // 합칠 수 있는 아이템의 경우
|
||||
{
|
||||
for (int i = 0; i < ITEM_SOCKET_MAX_NUM; ++i)
|
||||
if (item2->GetSocket(i) != item->GetSocket(i))
|
||||
@@ -6588,7 +6624,8 @@ bool CHARACTER::MoveItem(TItemPos Cell, TItemPos DestCell, BYTE count)
|
||||
sys_log(0, "%s: ITEM_STACK %s (window: %d, cell : %d) -> (window:%d, cell %d) count %d", GetName(), item->GetName(), Cell.window_type, Cell.cell,
|
||||
DestCell.window_type, DestCell.cell, count);
|
||||
|
||||
count = MIN(200 - item2->GetCount(), count);
|
||||
count = MIN(item2->GetStackRoom(), count);
|
||||
if (!count) return false;
|
||||
|
||||
item->SetCount(item->GetCount() - count);
|
||||
item2->SetCount(item2->GetCount() + count);
|
||||
@@ -6623,11 +6660,10 @@ bool CHARACTER::MoveItem(TItemPos Cell, TItemPos DestCell, BYTE count)
|
||||
sys_log(0, "%s: ITEM_SPLIT %s (window: %d, cell : %d) -> (window:%d, cell %d) count %d", GetName(), item->GetName(), Cell.window_type, Cell.cell,
|
||||
DestCell.window_type, DestCell.cell, count);
|
||||
|
||||
item->SetCount(item->GetCount() - count);
|
||||
LPITEM item2 = ITEM_MANAGER::instance().CreateItem(item->GetVnum(), count);
|
||||
|
||||
// copy socket -- by mhh
|
||||
FN_copy_item_socket(item2, item);
|
||||
LPITEM item2 = ITEM_MANAGER::instance().CreateItem(item->GetOriginalVnum(), count);
|
||||
if (!item2) return false;
|
||||
if (!item->CopyStackStateTo(item2)) { M2_DESTROY_ITEM(item2); return false; }
|
||||
if (!item->SetCount(item->GetCount() - count)) { M2_DESTROY_ITEM(item2); return false; }
|
||||
|
||||
item2->AddToCharacter(this, DestCell);
|
||||
|
||||
@@ -6795,19 +6831,21 @@ bool CHARACTER::PickupItem(DWORD dwVID)
|
||||
// 만약 주으려 하는 아이템이 엘크라면
|
||||
if (item->GetType() == ITEM_ELK)
|
||||
{
|
||||
if(!GiveGold(item->GetCount()))return false;
|
||||
const auto cubeGold=PortCubeDeferGroundGold(this,item);
|
||||
if(cubeGold==PortCubeGoldPickup::Blocked)return false;
|
||||
if(cubeGold==PortCubeGoldPickup::Ordinary&&!GiveGold(item->GetCount()))return false;
|
||||
item->RemoveFromGround();
|
||||
|
||||
M2_DESTROY_ITEM(item);
|
||||
|
||||
Save();
|
||||
if(cubeGold==PortCubeGoldPickup::Ordinary)Save();
|
||||
}
|
||||
// 평범한 아이템이라면
|
||||
else
|
||||
{
|
||||
if (item->IsStackable() && !IS_SET(item->GetAntiFlag(), ITEM_ANTIFLAG_STACK))
|
||||
{
|
||||
BYTE bCount = item->GetCount();
|
||||
DWORD bCount = item->GetCount();
|
||||
|
||||
#ifdef ENABLE_SPECIAL_STORAGE
|
||||
BYTE specialWin = 0;
|
||||
@@ -6824,7 +6862,7 @@ bool CHARACTER::PickupItem(DWORD dwVID)
|
||||
LPITEM item2 = GetItem(TItemPos(specialWin, i));
|
||||
if (!item2)
|
||||
continue;
|
||||
if (item2->GetVnum() == item->GetVnum())
|
||||
if (item2->CanStackWith(item))
|
||||
{
|
||||
int j;
|
||||
for (j = 0; j < ITEM_SOCKET_MAX_NUM; ++j)
|
||||
@@ -6833,12 +6871,12 @@ bool CHARACTER::PickupItem(DWORD dwVID)
|
||||
if (j != ITEM_SOCKET_MAX_NUM)
|
||||
continue;
|
||||
|
||||
BYTE bCount2 = MIN(200 - item2->GetCount(), bCount);
|
||||
DWORD bCount2 = MIN(item2->GetStackRoom(), bCount);
|
||||
bCount -= bCount2;
|
||||
item2->SetCount(item2->GetCount() + bCount2);
|
||||
if (bCount == 0)
|
||||
{
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("아이템 획득: %s"), item2->GetName());
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xbe\xc6\xc0\xcc\xc5\xdb \xc8\xb9\xb5\xe6: %s"), item2->GetName());
|
||||
M2_DESTROY_ITEM(item);
|
||||
if (item2->GetType() == ITEM_QUEST)
|
||||
quest::CQuestManager::instance().PickupItem(GetPlayerID(), item2);
|
||||
@@ -6857,7 +6895,7 @@ bool CHARACTER::PickupItem(DWORD dwVID)
|
||||
if (!item2)
|
||||
continue;
|
||||
|
||||
if (item2->GetVnum() == item->GetVnum())
|
||||
if (item2->CanStackWith(item))
|
||||
{
|
||||
int j;
|
||||
|
||||
@@ -6868,14 +6906,14 @@ bool CHARACTER::PickupItem(DWORD dwVID)
|
||||
if (j != ITEM_SOCKET_MAX_NUM)
|
||||
continue;
|
||||
|
||||
BYTE bCount2 = MIN(200 - item2->GetCount(), bCount);
|
||||
DWORD bCount2 = MIN(item2->GetStackRoom(), bCount);
|
||||
bCount -= bCount2;
|
||||
|
||||
item2->SetCount(item2->GetCount() + bCount2);
|
||||
|
||||
if (bCount == 0)
|
||||
{
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("아이템 획득: %s"), item2->GetName());
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xbe\xc6\xc0\xcc\xc5\xdb \xc8\xb9\xb5\xe6: %s"), item2->GetName());
|
||||
M2_DESTROY_ITEM(item);
|
||||
if (item2->GetType() == ITEM_QUEST)
|
||||
quest::CQuestManager::instance().PickupItem (GetPlayerID(), item2);
|
||||
@@ -6964,7 +7002,7 @@ bool CHARACTER::PickupItem(DWORD dwVID)
|
||||
char szHint[32+1];
|
||||
snprintf(szHint, sizeof(szHint), "%s %u %u", item->GetName(), item->GetCount(), item->GetOriginalVnum());
|
||||
LogManager::instance().ItemLog(this, item, "GET", szHint);
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("아이템 획득: %s"), item->GetName());
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xbe\xc6\xc0\xcc\xc5\xdb \xc8\xb9\xb5\xe6: %s"), item->GetName());
|
||||
|
||||
if (item->GetType() == ITEM_QUEST)
|
||||
quest::CQuestManager::instance().PickupItem (GetPlayerID(), item);
|
||||
@@ -7023,11 +7061,11 @@ bool CHARACTER::PickupItem(DWORD dwVID)
|
||||
LogManager::instance().ItemLog(owner, item, "GET", szHint);
|
||||
|
||||
if (owner == this)
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("아이템 획득: %s"), item->GetName());
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xbe\xc6\xc0\xcc\xc5\xdb \xc8\xb9\xb5\xe6: %s"), item->GetName());
|
||||
else
|
||||
{
|
||||
owner->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("아이템 획득: %s 님으로부터 %s"), GetName(), item->GetName());
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("아이템 전달: %s 님에게 %s"), owner->GetName(), item->GetName());
|
||||
owner->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xbe\xc6\xc0\xcc\xc5\xdb \xc8\xb9\xb5\xe6: %s \xb4\xd4\xc0\xb8\xb7\xce\xba\xce\xc5\xcd %s"), GetName(), item->GetName());
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xbe\xc6\xc0\xcc\xc5\xdb \xc0\xfc\xb4\xde: %s \xb4\xd4\xbf\xa1\xb0\xd4 %s"), owner->GetName(), item->GetName());
|
||||
}
|
||||
|
||||
if (item->GetType() == ITEM_QUEST)
|
||||
@@ -7602,19 +7640,34 @@ void CHARACTER::RemoveSpecifyTypeItem(BYTE type, DWORD count)
|
||||
}
|
||||
}
|
||||
|
||||
void CHARACTER::AutoGiveItem(LPITEM item, bool longOwnerShip)
|
||||
LPITEM CHARACTER::AutoGiveItem(LPITEM item, bool longOwnerShip)
|
||||
{
|
||||
if (NULL == item)
|
||||
{
|
||||
sys_err ("NULL point.");
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
if (item->GetOwner())
|
||||
{
|
||||
sys_err ("item %d 's owner exists!",item->GetID());
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (item->IsStackable())
|
||||
{
|
||||
DWORD remaining = item->GetCount();
|
||||
for (int cell = 0; cell < INVENTORY_MAX_NUM; ++cell)
|
||||
{
|
||||
LPITEM target = GetInventoryItem(cell);
|
||||
if (!target || !target->CanStackWith(item)) continue;
|
||||
const DWORD moved = std::min(remaining, target->GetStackRoom());
|
||||
if (!moved) continue;
|
||||
target->SetCount(target->GetCount() + moved);
|
||||
remaining -= moved;
|
||||
if (!remaining) { M2_DESTROY_ITEM(item); return target; }
|
||||
}
|
||||
item->SetCount(remaining);
|
||||
}
|
||||
#ifdef ENABLE_SPECIAL_STORAGE
|
||||
if (item->IsStackable() && !IS_SET(item->GetAntiFlag(), ITEM_ANTIFLAG_STACK))
|
||||
{
|
||||
@@ -7633,7 +7686,7 @@ void CHARACTER::AutoGiveItem(LPITEM item, bool longOwnerShip)
|
||||
LPITEM item2 = GetItem(TItemPos(specialWin, i));
|
||||
if (!item2)
|
||||
continue;
|
||||
if (item2->GetVnum() == item->GetVnum())
|
||||
if (item2->CanStackWith(item))
|
||||
{
|
||||
bool socketMatch = true;
|
||||
for (int s = 0; s < ITEM_SOCKET_MAX_NUM; ++s)
|
||||
@@ -7647,7 +7700,7 @@ void CHARACTER::AutoGiveItem(LPITEM item, bool longOwnerShip)
|
||||
if (!socketMatch)
|
||||
continue;
|
||||
|
||||
DWORD bCount2 = MIN(200 - item2->GetCount(), bCount);
|
||||
DWORD bCount2 = MIN(item2->GetStackRoom(), bCount);
|
||||
bCount -= bCount2;
|
||||
item2->SetCount(item2->GetCount() + bCount2);
|
||||
if (bCount == 0)
|
||||
@@ -7655,7 +7708,7 @@ void CHARACTER::AutoGiveItem(LPITEM item, bool longOwnerShip)
|
||||
if (item2->GetType() == ITEM_QUEST || item2->GetType() == ITEM_MATERIAL)
|
||||
quest::CQuestManager::instance().PickupItem(GetPlayerID(), item2);
|
||||
M2_DESTROY_ITEM(item);
|
||||
return;
|
||||
return item2;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7734,132 +7787,44 @@ void CHARACTER::AutoGiveItem(LPITEM item, bool longOwnerShip)
|
||||
item->SetOwnership (this, 60);
|
||||
LogManager::instance().ItemLog(this, item, "SYSTEM_DROP", item->GetName());
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
LPITEM CHARACTER::AutoGiveItem(DWORD dwItemVnum, BYTE bCount, int iRarePct, bool bMsg)
|
||||
LPITEM CHARACTER::AutoGiveItem(DWORD dwItemVnum, DWORD bCount, int iRarePct, bool bMsg)
|
||||
{
|
||||
TItemTable * p = ITEM_MANAGER::instance().GetTable(dwItemVnum);
|
||||
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
DBManager::instance().SendMoneyLog(MONEY_LOG_DROP, dwItemVnum, bCount);
|
||||
|
||||
if (p->dwFlags & ITEM_FLAG_STACKABLE && p->bType != ITEM_BLEND)
|
||||
{
|
||||
for (int i = 0; i < INVENTORY_MAX_NUM; ++i)
|
||||
{
|
||||
LPITEM item = GetInventoryItem(i);
|
||||
|
||||
if (!item)
|
||||
continue;
|
||||
|
||||
if (item->GetVnum() == dwItemVnum && FN_check_item_socket(item))
|
||||
{
|
||||
if (IS_SET(p->dwFlags, ITEM_FLAG_MAKECOUNT))
|
||||
{
|
||||
if (bCount < p->alValues[1])
|
||||
bCount = p->alValues[1];
|
||||
}
|
||||
|
||||
BYTE bCount2 = MIN(200 - item->GetCount(), bCount);
|
||||
bCount -= bCount2;
|
||||
|
||||
item->SetCount(item->GetCount() + bCount2);
|
||||
|
||||
if (bCount == 0)
|
||||
{
|
||||
if (bMsg)
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("아이템 획득: %s"), item->GetName());
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LPITEM item = ITEM_MANAGER::instance().CreateItem(dwItemVnum, bCount, 0, true);
|
||||
|
||||
if (!item)
|
||||
{
|
||||
sys_err("cannot create item by vnum %u (name: %s)", dwItemVnum, GetName());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (item->GetType() == ITEM_BLEND)
|
||||
{
|
||||
for (int i=0; i < INVENTORY_MAX_NUM; i++)
|
||||
{
|
||||
LPITEM inv_item = GetInventoryItem(i);
|
||||
|
||||
if (inv_item == NULL) continue;
|
||||
|
||||
if (inv_item->GetType() == ITEM_BLEND)
|
||||
{
|
||||
if (inv_item->GetVnum() == item->GetVnum())
|
||||
{
|
||||
if (inv_item->GetSocket(0) == item->GetSocket(0) &&
|
||||
inv_item->GetSocket(1) == item->GetSocket(1) &&
|
||||
inv_item->GetSocket(2) == item->GetSocket(2) &&
|
||||
inv_item->GetCount() < ITEM_MAX_COUNT)
|
||||
{
|
||||
inv_item->SetCount(inv_item->GetCount() + item->GetCount());
|
||||
return inv_item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int iEmptyCell;
|
||||
if (item->IsDragonSoul())
|
||||
{
|
||||
iEmptyCell = GetEmptyDragonSoulInventory(item);
|
||||
}
|
||||
else
|
||||
iEmptyCell = GetEmptyInventory(item->GetSize());
|
||||
|
||||
if (iEmptyCell != -1)
|
||||
{
|
||||
if (bMsg)
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("아이템 획득: %s"), item->GetName());
|
||||
|
||||
if (item->IsDragonSoul())
|
||||
item->AddToCharacter(this, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyCell));
|
||||
else
|
||||
item->AddToCharacter(this, TItemPos(INVENTORY, iEmptyCell));
|
||||
LogManager::instance().ItemLog(this, item, "SYSTEM", item->GetName());
|
||||
|
||||
if (item->GetType() == ITEM_USE && item->GetSubType() == USE_POTION)
|
||||
{
|
||||
TQuickslot * pSlot;
|
||||
|
||||
if (GetQuickslot(0, &pSlot) && pSlot->type == QUICKSLOT_TYPE_NONE)
|
||||
{
|
||||
TQuickslot slot;
|
||||
slot.type = QUICKSLOT_TYPE_ITEM;
|
||||
slot.pos = iEmptyCell;
|
||||
SetQuickslot(0, slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
item->AddToGround(GetMapIndex(), GetXYZ());
|
||||
item->StartDestroyEvent();
|
||||
// 안티 드랍 flag가 걸려있는 아이템의 경우,
|
||||
// 인벤에 빈 공간이 없어서 어쩔 수 없이 떨어트리게 되면,
|
||||
// ownership을 아이템이 사라질 때까지(300초) 유지한다.
|
||||
if (IS_SET(item->GetAntiFlag(), ITEM_ANTIFLAG_DROP))
|
||||
item->SetOwnership(this, 300);
|
||||
else
|
||||
item->SetOwnership(this, 60);
|
||||
LogManager::instance().ItemLog(this, item, "SYSTEM_DROP", item->GetName());
|
||||
}
|
||||
|
||||
sys_log(0,
|
||||
"7: %d %d", dwItemVnum, bCount);
|
||||
return item;
|
||||
const TItemTable* proto = ITEM_MANAGER::instance().GetTable(dwItemVnum);
|
||||
if (!proto || !bCount) return NULL;
|
||||
unsigned limit = PortMaterialStackPolicy::GrantLimit(proto->bType,
|
||||
(proto->dwFlags & ITEM_FLAG_STACKABLE) != 0,
|
||||
(proto->dwAntiFlags & ITEM_ANTIFLAG_STACK) != 0, dwItemVnum);
|
||||
if ((PortMaterialStackPolicy::LegacyGrowthMode() || quest::CQuestManager::instance().GetEventFlag("material_stack_legacy_mode")))
|
||||
limit = std::min(limit, 200u);
|
||||
if ((proto->dwFlags & ITEM_FLAG_MAKECOUNT) && proto->alValues[1] > 0)
|
||||
bCount = std::max(bCount, DWORD(proto->alValues[1]));
|
||||
LPITEM result = NULL;
|
||||
while (bCount)
|
||||
{
|
||||
const DWORD chunk = std::min(bCount, limit);
|
||||
LPITEM item = ITEM_MANAGER::instance().CreateItem(dwItemVnum, chunk, 0, true, iRarePct);
|
||||
if (!item) { sys_err("AutoGiveItem failed: vnum %u remaining %u", dwItemVnum, bCount); return result; }
|
||||
if (item->GetCount() != chunk && !item->SetCount(chunk)) { M2_DESTROY_ITEM(item); return result; }
|
||||
result = AutoGiveItem(item);
|
||||
if (!result) { M2_DESTROY_ITEM(item); return NULL; }
|
||||
DBManager::instance().SendMoneyLog(MONEY_LOG_DROP, dwItemVnum, chunk);
|
||||
bCount -= chunk;
|
||||
}
|
||||
if (result && bMsg)
|
||||
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("아이템 획득: %s"), result->GetName());
|
||||
if (result && result->GetWindow() == INVENTORY && result->GetType() == ITEM_USE && result->GetSubType() == USE_POTION)
|
||||
{
|
||||
TQuickslot* slot;
|
||||
if (GetQuickslot(0, &slot) && slot->type == QUICKSLOT_TYPE_NONE)
|
||||
{
|
||||
TQuickslot newSlot; newSlot.type = QUICKSLOT_TYPE_ITEM; newSlot.pos = result->GetCell();
|
||||
SetQuickslot(0, newSlot);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CHARACTER::GiveItem(LPCHARACTER victim, TItemPos Cell)
|
||||
@@ -8282,6 +8247,14 @@ bool CHARACTER::GiveItemFromSpecialItemGroup(DWORD dwGroupNum, std::vector<DWORD
|
||||
}
|
||||
break;
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case CSpecialItemGroup::BLEEDING:
|
||||
{
|
||||
AttackedByBleeding(NULL);
|
||||
bSuccess = true;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case CSpecialItemGroup::MOB_GROUP:
|
||||
{
|
||||
int sx = GetX() - number(300, 500);
|
||||
@@ -8351,6 +8324,10 @@ bool CHARACTER::ItemProcess_Hair(LPITEM item, int iDestCell)
|
||||
hair -= 69750;
|
||||
break;
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case JOB_WOLFMAN:
|
||||
break; // NOTE: ?? ?ì¾î??µå´? ¾? ¾²??¹?·? ??½º. (?ö?ç ?ì¾î½?½º???º ??¹? ??½º?¬?¸·? ´ë?¼ µ? »ó????)
|
||||
#endif
|
||||
default :
|
||||
return false;
|
||||
break;
|
||||
@@ -8626,6 +8603,16 @@ bool CHARACTER::IsValidItemPosition(TItemPos Pos) const
|
||||
case SWITCHBOT:
|
||||
return cell < SWITCHBOT_SLOT_COUNT;
|
||||
|
||||
#ifdef ENABLE_SPECIAL_STORAGE
|
||||
// PORT: without these GetItem() returned NULL for every special storage cell
|
||||
case UPGRADE_INVENTORY:
|
||||
case BOOK_INVENTORY:
|
||||
case STONE_INVENTORY:
|
||||
case CHANGE_INVENTORY:
|
||||
case COSTUME_INVENTORY:
|
||||
return cell < SPECIAL_INVENTORY_MAX_NUM;
|
||||
#endif
|
||||
|
||||
case SAFEBOX:
|
||||
if (NULL != m_pkSafebox)
|
||||
return m_pkSafebox->IsValidPosition(cell);
|
||||
@@ -8679,6 +8666,12 @@ bool CHARACTER::CanEquipNow(const LPITEM item, const TItemPos& srcCell, const TI
|
||||
if (item->GetAntiFlag() & ITEM_ANTIFLAG_SURA)
|
||||
return false;
|
||||
break;
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case JOB_WOLFMAN:
|
||||
if (item->GetAntiFlag() & ITEM_ANTIFLAG_WOLFMAN)
|
||||
return false;
|
||||
break; // TODO: ¼ö???· ¾????? ?ø¿ë°¡´?¿©º? ?³¸®
|
||||
#endif
|
||||
}
|
||||
|
||||
for (int i = 0; i < ITEM_LIMIT_MAX_NUM; ++i)
|
||||
|
||||
@@ -880,6 +880,12 @@ bool CHARACTER_MANAGER::GetCharactersByRaceNum(DWORD dwRaceNum, CharacterVectorI
|
||||
#define FIND_JOB_SHAMAN_2 (1 << 14)
|
||||
#define FIND_JOB_SHAMAN (FIND_JOB_SHAMAN_0 | FIND_JOB_SHAMAN_1 | FIND_JOB_SHAMAN_2)
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
#define FIND_JOB_WOLFMAN_0 (1 << 15)
|
||||
#define FIND_JOB_WOLFMAN_1 (1 << 16)
|
||||
#define FIND_JOB_WOLFMAN_2 (1 << 17)
|
||||
#define FIND_JOB_WOLFMAN (FIND_JOB_WOLFMAN_0 | FIND_JOB_WOLFMAN_1 | FIND_JOB_WOLFMAN_2)
|
||||
#endif
|
||||
//
|
||||
// (job+1)*3+(skill_group)
|
||||
//
|
||||
|
||||
@@ -81,6 +81,79 @@ EVENTFUNC(poison_event)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
const int bleeding_damage_rate[MOB_RANK_MAX_NUM] =
|
||||
{
|
||||
80, 50, 40, 30, 25, 1
|
||||
};
|
||||
|
||||
int GetBleedingDamageRate(LPCHARACTER ch)
|
||||
{
|
||||
int iRate;
|
||||
|
||||
if (ch->IsPC())
|
||||
iRate = 50;
|
||||
else
|
||||
iRate = bleeding_damage_rate[ch->GetMobRank()];
|
||||
|
||||
iRate = MAX(0, iRate - ch->GetPoint(POINT_BLEEDING_REDUCE));
|
||||
#if defined(ENABLE_WOLFMAN_CHARACTER) && defined(USE_ITEM_BLEEDING_AS_POISON)
|
||||
iRate = MAX(0, iRate - ch->GetPoint(POINT_POISON_REDUCE));
|
||||
#endif
|
||||
return iRate;
|
||||
}
|
||||
|
||||
EVENTINFO(TBleedingEventInfo)
|
||||
{
|
||||
DynamicCharacterPtr ch;
|
||||
int count;
|
||||
DWORD attacker_pid;
|
||||
|
||||
TBleedingEventInfo()
|
||||
: ch()
|
||||
, count(0)
|
||||
, attacker_pid(0)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
EVENTFUNC(bleeding_event)
|
||||
{
|
||||
TBleedingEventInfo * info = dynamic_cast<TBleedingEventInfo *>( event->info );
|
||||
|
||||
if ( info == NULL )
|
||||
{
|
||||
sys_err( "bleeding_event> <Factor> Null pointer" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
LPCHARACTER ch = info->ch;
|
||||
|
||||
if (ch == NULL) { // <Factor>
|
||||
return 0;
|
||||
}
|
||||
LPCHARACTER pkAttacker = CHARACTER_MANAGER::instance().FindByPID(info->attacker_pid);
|
||||
|
||||
int dam = ch->GetMaxHP() * GetBleedingDamageRate(ch) / 1000;
|
||||
if (test_server) ch->ChatPacket(CHAT_TYPE_NOTICE, "Bleeding Damage %d", dam);
|
||||
|
||||
if (ch->Damage(pkAttacker, dam, DAMAGE_TYPE_BLEEDING))
|
||||
{
|
||||
ch->m_pkBleedingEvent = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
--info->count;
|
||||
|
||||
if (info->count)
|
||||
return PASSES_PER_SEC(3);
|
||||
else
|
||||
{
|
||||
ch->m_pkBleedingEvent = NULL;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
EVENTINFO(TFireEventInfo)
|
||||
{
|
||||
DynamicCharacterPtr ch;
|
||||
@@ -162,6 +235,12 @@ static int poison_level_adjust[9] =
|
||||
100, 90, 80, 70, 50, 30, 10, 5, 0
|
||||
};
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
static int bleeding_level_adjust[9] =
|
||||
{
|
||||
100, 90, 80, 70, 50, 30, 10, 5, 0
|
||||
};
|
||||
#endif
|
||||
void CHARACTER::AttackedByFire(LPCHARACTER pkAttacker, int amount, int count)
|
||||
{
|
||||
if (m_pkFireEvent)
|
||||
@@ -187,6 +266,13 @@ void CHARACTER::AttackedByPoison(LPCHARACTER pkAttacker)
|
||||
if (m_bHasPoisoned && !IsPC()) // 몬스터는 독이 한번만 걸린다.
|
||||
return;
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
if (m_pkBleedingEvent)
|
||||
return;
|
||||
|
||||
if (m_bHasBled && !IsPC()) // 몬스터는 독이 한번만 걸린다.
|
||||
return;
|
||||
#endif
|
||||
if (pkAttacker && pkAttacker->GetLevel() < GetLevel())
|
||||
{
|
||||
int delta = GetLevel() - pkAttacker->GetLevel();
|
||||
@@ -222,6 +308,56 @@ void CHARACTER::AttackedByPoison(LPCHARACTER pkAttacker)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
void CHARACTER::AttackedByBleeding(LPCHARACTER pkAttacker)
|
||||
{
|
||||
if (m_pkBleedingEvent)
|
||||
return;
|
||||
|
||||
if (m_bHasBled && !IsPC()) // 몬스터는 독이 한번만 걸린다.
|
||||
return;
|
||||
|
||||
if (m_pkPoisonEvent)
|
||||
return;
|
||||
|
||||
if (m_bHasPoisoned && !IsPC()) // 몬스터는 독이 한번만 걸린다.
|
||||
return;
|
||||
|
||||
if (pkAttacker && pkAttacker->GetLevel() < GetLevel())
|
||||
{
|
||||
int delta = GetLevel() - pkAttacker->GetLevel();
|
||||
|
||||
if (delta > 8)
|
||||
delta = 8;
|
||||
|
||||
if (number(1, 100) > bleeding_level_adjust[delta])
|
||||
return;
|
||||
}
|
||||
|
||||
/*if (IsImmune(IMMUNE_BLEEDING))
|
||||
return;*/
|
||||
|
||||
// 독 내성 굴림 실패, 독에 걸렸다!
|
||||
m_bHasBled = true;
|
||||
|
||||
AddAffect(AFFECT_BLEEDING, POINT_NONE, 0, AFF_BLEEDING, BLEEDING_LENGTH + 1, 0, true);
|
||||
|
||||
TBleedingEventInfo* info = AllocEventInfo<TBleedingEventInfo>();
|
||||
|
||||
info->ch = this;
|
||||
info->count = 10;
|
||||
info->attacker_pid = pkAttacker?pkAttacker->GetPlayerID():0;
|
||||
|
||||
m_pkBleedingEvent = event_create(bleeding_event, info, 1);
|
||||
|
||||
if (test_server && pkAttacker)
|
||||
{
|
||||
char buf[256];
|
||||
snprintf(buf, sizeof(buf), "BLEEDING %s -> %s", pkAttacker->GetName(), GetName());
|
||||
pkAttacker->ChatPacket(CHAT_TYPE_INFO, "%s", buf);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
void CHARACTER::RemoveFire()
|
||||
{
|
||||
RemoveAffect(AFFECT_FIRE);
|
||||
@@ -234,6 +370,13 @@ void CHARACTER::RemovePoison()
|
||||
event_cancel(&m_pkPoisonEvent);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
void CHARACTER::RemoveBleeding()
|
||||
{
|
||||
RemoveAffect(AFFECT_BLEEDING);
|
||||
event_cancel(&m_pkBleedingEvent);
|
||||
}
|
||||
#endif
|
||||
void CHARACTER::ApplyMobAttribute(const TMobTable* table)
|
||||
{
|
||||
for (int i = 0; i < MOB_ENCHANTS_MAX_NUM; ++i)
|
||||
@@ -242,11 +385,23 @@ void CHARACTER::ApplyMobAttribute(const TMobTable* table)
|
||||
ApplyPoint(aiMobEnchantApplyIdx[i], table->cEnchants[i]);
|
||||
}
|
||||
|
||||
#if defined(ENABLE_WOLFMAN_CHARACTER) && defined(USE_MOB_BLEEDING_AS_POISON)
|
||||
if (table->cEnchants[MOB_ENCHANT_POISON] != 0)
|
||||
ApplyPoint(APPLY_BLEEDING_PCT, table->cEnchants[MOB_ENCHANT_POISON]/50); // @warme009
|
||||
#endif
|
||||
for (int i = 0; i < MOB_RESISTS_MAX_NUM; ++i)
|
||||
{
|
||||
if (table->cResists[i] != 0)
|
||||
ApplyPoint(aiMobResistsApplyIdx[i], table->cResists[i]);
|
||||
}
|
||||
#if defined(ENABLE_WOLFMAN_CHARACTER) && defined(USE_MOB_CLAW_AS_DAGGER)
|
||||
if (table->cResists[MOB_RESIST_DAGGER] != 0)
|
||||
ApplyPoint(APPLY_RESIST_CLAW, table->cResists[MOB_RESIST_DAGGER]);
|
||||
#endif
|
||||
#if defined(ENABLE_WOLFMAN_CHARACTER) && defined(USE_MOB_BLEEDING_AS_POISON)
|
||||
if (table->cResists[MOB_RESIST_POISON] != 0)
|
||||
ApplyPoint(APPLY_BLEEDING_REDUCE, table->cResists[MOB_RESIST_POISON]);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CHARACTER::IsImmune(DWORD dwImmuneFlag)
|
||||
|
||||
@@ -223,6 +223,11 @@ bool CHARACTER::IsLearnableSkill(DWORD dwSkillVnum) const
|
||||
if (pkSkill->dwType - 1 == GetJob())
|
||||
return true;
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
// ¼öÀÎÁ· ½ºÅ³
|
||||
if (7 == pkSkill->dwType && JOB_WOLFMAN == GetJob())
|
||||
return true;
|
||||
#endif
|
||||
if (6 == pkSkill->dwType)
|
||||
{
|
||||
if (SKILL_7_A_ANTI_TANHWAN <= dwSkillVnum && dwSkillVnum <= SKILL_7_D_ANTI_YONGBI)
|
||||
@@ -443,7 +448,11 @@ bool CHARACTER::LearnSkillByBook(DWORD dwSkillVnum, BYTE bProb)
|
||||
// bType이 0이면 처음부터 책으로 수련 가능
|
||||
if (pkSk->dwType != 0)
|
||||
{
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
if (GetSkillMasterType(dwSkillVnum) != SKILL_MASTER && (dwSkillVnum >= SKILL_FINISH && dwSkillVnum <= SKILL_ILIPUNGU))
|
||||
#else
|
||||
if (GetSkillMasterType(dwSkillVnum) != SKILL_MASTER && (dwSkillVnum >= SKILL_FINISH && dwSkillVnum <= SKILL_CHEONUN))
|
||||
#endif
|
||||
{
|
||||
if (GetSkillMasterType(dwSkillVnum) > SKILL_MASTER)
|
||||
{
|
||||
@@ -674,6 +683,9 @@ bool CHARACTER::SkillLevelDown(DWORD dwVnum)
|
||||
case 3:
|
||||
case 4:
|
||||
case 6:
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case 7:
|
||||
#endif
|
||||
idx = POINT_SKILL;
|
||||
break;
|
||||
case 5:
|
||||
@@ -760,7 +772,11 @@ void CHARACTER::SkillLevelUp(DWORD dwVnum, BYTE bMethod)
|
||||
else if (bMethod == SKILL_UP_BY_BOOK)
|
||||
{
|
||||
if (pkSk->dwType != 0) // 직업에 속하지 않았거나 포인트로 올릴수 없는 스킬은 처음부터 책으로 배울 수 있다.
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
if (GetSkillMasterType(pkSk->dwVnum) != SKILL_MASTER && (pkSk->dwVnum < SKILL_FINISH || pkSk->dwVnum > SKILL_ILIPUNGU))
|
||||
#else
|
||||
if (GetSkillMasterType(pkSk->dwVnum) != SKILL_MASTER && (pkSk->dwVnum < SKILL_FINISH || pkSk->dwVnum > SKILL_CHEONUN))
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -790,6 +806,9 @@ void CHARACTER::SkillLevelUp(DWORD dwVnum, BYTE bMethod)
|
||||
case 3:
|
||||
case 4:
|
||||
case 6:
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case 7:
|
||||
#endif
|
||||
idx = POINT_SKILL;
|
||||
break;
|
||||
|
||||
@@ -1258,6 +1277,19 @@ struct FuncSplashDamage
|
||||
|
||||
iAmount = (int) (iAmount * adjust);
|
||||
}
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
else if (m_pkSk->dwVnum == SKILL_GONGDAB)
|
||||
{
|
||||
float adjust = 1.0;
|
||||
|
||||
if (m_pkChr->GetWear(WEAR_WEAPON) && m_pkChr->GetWear(WEAR_WEAPON)->GetSubType() == WEAPON_CLAW)
|
||||
{
|
||||
adjust = 1.35f;
|
||||
}
|
||||
|
||||
iAmount = (int)(iAmount * adjust);
|
||||
}
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//sys_log(0, "name: %s skill: %s amount %d to %s", m_pkChr->GetName(), m_pkSk->szName, iAmount, pkChrVictim->GetName());
|
||||
|
||||
@@ -1308,6 +1340,14 @@ struct FuncSplashDamage
|
||||
case WEAPON_FAN:
|
||||
iDam = iDam * (100 - pkChrVictim->GetPoint(POINT_RESIST_FAN)) / 100;
|
||||
break;
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case WEAPON_CLAW:
|
||||
iDam = iDam * (100 - pkChrVictim->GetPoint(POINT_RESIST_CLAW)) / 100;
|
||||
#if defined(ENABLE_WOLFMAN_CHARACTER) && defined(USE_ITEM_CLAW_AS_DAGGER)
|
||||
iDam = iDam * (100 - pkChrVictim->GetPoint(POINT_RESIST_DAGGER)) / 100;
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!bIgnoreDefense)
|
||||
@@ -1433,7 +1473,11 @@ struct FuncSplashDamage
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
if (IS_SET(m_pkSk->dwFlag, SKILL_FLAG_SLOW | SKILL_FLAG_STUN | SKILL_FLAG_FIRE_CONT | SKILL_FLAG_POISON | SKILL_FLAG_BLEEDING))
|
||||
#else
|
||||
if (IS_SET(m_pkSk->dwFlag, SKILL_FLAG_SLOW | SKILL_FLAG_STUN | SKILL_FLAG_FIRE_CONT | SKILL_FLAG_POISON))
|
||||
#endif
|
||||
{
|
||||
int iPct = (int) m_pkSk->kPointPoly2.Eval();
|
||||
int iDur = (int) m_pkSk->kDurationPoly2.Eval();
|
||||
@@ -1471,6 +1515,13 @@ struct FuncSplashDamage
|
||||
if (number(1, 100) <= iPct)
|
||||
pkChrVictim->AttackedByPoison(m_pkChr);
|
||||
}
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
else if (IS_SET(m_pkSk->dwFlag, SKILL_FLAG_BLEEDING))
|
||||
{
|
||||
if (number(1, 100) <= iPct)
|
||||
pkChrVictim->AttackedByBleeding(m_pkChr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (IS_SET(m_pkSk->dwFlag, SKILL_FLAG_CRUSH | SKILL_FLAG_CRUSH_LONG) &&
|
||||
@@ -1977,6 +2028,35 @@ int CHARACTER::ComputeSkillAtPosition(DWORD dwVnum, const PIXEL_POSITION& posTar
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
struct FComputeSkillParty
|
||||
{
|
||||
FComputeSkillParty(DWORD dwVnum, LPCHARACTER pkAttacker, BYTE bSkillLevel = 0)
|
||||
: m_dwVnum(dwVnum), m_pkAttacker(pkAttacker), m_bSkillLevel(bSkillLevel)
|
||||
{
|
||||
}
|
||||
|
||||
void operator () (LPCHARACTER ch)
|
||||
{
|
||||
m_pkAttacker->ComputeSkill(m_dwVnum, ch, m_bSkillLevel);
|
||||
}
|
||||
|
||||
DWORD m_dwVnum;
|
||||
LPCHARACTER m_pkAttacker;
|
||||
BYTE m_bSkillLevel;
|
||||
};
|
||||
|
||||
int CHARACTER::ComputeSkillParty(DWORD dwVnum, LPCHARACTER pkVictim, BYTE bSkillLevel)
|
||||
{
|
||||
FComputeSkillParty f(dwVnum, pkVictim, bSkillLevel);
|
||||
if (GetParty() && GetParty()->GetNearMemberCount())
|
||||
GetParty()->ForEachNearMember(f);
|
||||
else
|
||||
f(this);
|
||||
|
||||
return BATTLE_NONE;
|
||||
}
|
||||
#endif
|
||||
// bSkillLevel 인자가 0이 아닐 경우에는 m_abSkillLevels를 사용하지 않고 강제로
|
||||
// bSkillLevel로 계산한다.
|
||||
int CHARACTER::ComputeSkill(DWORD dwVnum, LPCHARACTER pkVictim, BYTE bSkillLevel)
|
||||
@@ -2612,6 +2692,10 @@ bool CHARACTER::UseSkill(DWORD dwVnum, LPCHARACTER pkVictim, bool bUseGrandMaste
|
||||
|
||||
if (IS_SET(pkSk->dwFlag, SKILL_FLAG_SELFONLY))
|
||||
pkVictim = this;
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
else if (IS_SET(pkSk->dwFlag, SKILL_FLAG_PARTY))
|
||||
pkVictim = this;
|
||||
#endif
|
||||
|
||||
if (pkSk->dwVnum == SKILL_MUYEONG || pkSk->IsChargeSkill() && !IsAffectFlag(AFF_TANHWAN_DASH) && !pkVictim)
|
||||
{
|
||||
@@ -2645,14 +2729,33 @@ bool CHARACTER::UseSkill(DWORD dwVnum, LPCHARACTER pkVictim, bool bUseGrandMaste
|
||||
}
|
||||
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
if(pkVictim && GetParty() && (dwVnum == 94 || dwVnum == 95 || dwVnum == 96 || dwVnum == 110 || dwVnum == 111))
|
||||
{
|
||||
if(pkVictim->GetParty()){
|
||||
if(pkVictim->GetParty() == GetParty())
|
||||
{
|
||||
ComputeSkillParty(dwVnum, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (IS_SET(pkSk->dwFlag, SKILL_FLAG_SELFONLY))
|
||||
ComputeSkill(dwVnum, this);
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
else if (IS_SET(pkSk->dwFlag, SKILL_FLAG_PARTY))
|
||||
ComputeSkillParty(dwVnum, this);
|
||||
#endif
|
||||
else if (!IS_SET(pkSk->dwFlag, SKILL_FLAG_ATTACK))
|
||||
ComputeSkill(dwVnum, pkVictim);
|
||||
else if (dwVnum == SKILL_BYEURAK)
|
||||
ComputeSkill(dwVnum, pkVictim);
|
||||
else if (dwVnum == SKILL_MUYEONG || pkSk->IsChargeSkill())
|
||||
ComputeSkill(dwVnum, pkVictim);
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
else if (dwVnum == SKILL_METEO)
|
||||
ComputeSkill(dwVnum, pkVictim);
|
||||
#endif
|
||||
|
||||
m_dwLastSkillTime = get_dword_time();
|
||||
|
||||
@@ -2786,6 +2889,61 @@ void CHARACTER::StopMuyeongEvent()
|
||||
event_cancel(&m_pkMuyeongEvent);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
EVENTINFO(cheonun_event_info)
|
||||
{
|
||||
DynamicCharacterPtr ch;
|
||||
long lApplyCheonun;
|
||||
};
|
||||
|
||||
// SKILL_CHEONUN: every 12 s, lApplyCheonun % chance of a 5 s full damage block (AFF_CHUNWOON_MOOJUK)
|
||||
EVENTFUNC(skill_cheonun_event)
|
||||
{
|
||||
cheonun_event_info* info = dynamic_cast<cheonun_event_info*>(event->info);
|
||||
|
||||
if (info == NULL)
|
||||
{
|
||||
sys_err("skill_cheonun_event> <Factor> Null pointer");
|
||||
return 0;
|
||||
}
|
||||
|
||||
LPCHARACTER ch = info->ch;
|
||||
long lValue = info->lApplyCheonun;
|
||||
|
||||
if (ch == NULL || lValue == 0)
|
||||
return 0;
|
||||
|
||||
if (!ch->IsAffectFlag(AFF_CHEONUN))
|
||||
{
|
||||
ch->StopCheonunEvent();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (number(1, 100) <= lValue)
|
||||
ch->AddAffect(2000, POINT_NONE, 0, AFF_CHUNWOON_MOOJUK, 5, 0, true);
|
||||
|
||||
return PASSES_PER_SEC(12);
|
||||
}
|
||||
|
||||
void CHARACTER::StartCheonunEvent(long lApplyValue)
|
||||
{
|
||||
if (m_pkCheonunEvent)
|
||||
return;
|
||||
|
||||
cheonun_event_info* info = AllocEventInfo<cheonun_event_info>();
|
||||
|
||||
info->ch = this;
|
||||
info->lApplyCheonun = lApplyValue;
|
||||
|
||||
m_pkCheonunEvent = event_create(skill_cheonun_event, info, PASSES_PER_SEC(1));
|
||||
}
|
||||
|
||||
void CHARACTER::StopCheonunEvent()
|
||||
{
|
||||
event_cancel(&m_pkCheonunEvent);
|
||||
}
|
||||
#endif
|
||||
|
||||
void CHARACTER::SkillLearnWaitMoreTimeMessage(DWORD ms)
|
||||
{
|
||||
//const char* str = "";
|
||||
@@ -3018,7 +3176,13 @@ bool CHARACTER::IsUsableSkillMotion(DWORD dwMotionIndex) const
|
||||
{
|
||||
DWORD selfJobGroup = (GetJob()+1) * 10 + GetSkillGroup();
|
||||
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
const DWORD SKILL_NUM = 184;
|
||||
#elif defined(ENABLE_WOLFMAN_CHARACTER)
|
||||
const DWORD SKILL_NUM = 176;
|
||||
#else
|
||||
const DWORD SKILL_NUM = 158;
|
||||
#endif
|
||||
static DWORD s_anSkill2JobGroup[SKILL_NUM] = {
|
||||
0, // common_skill 0
|
||||
11, // job_skill 1
|
||||
@@ -3178,10 +3342,44 @@ bool CHARACTER::IsUsableSkillMotion(DWORD dwMotionIndex) const
|
||||
0, // job_skill 155
|
||||
0, // job_skill 156
|
||||
0, // job_skill 157
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
0, // empty(reserved) 158
|
||||
0, // empty(reserved) 159
|
||||
0, // empty(reserved) 160
|
||||
0, // empty(reserved) 161
|
||||
0, // empty(reserved) 162
|
||||
0, // empty(reserved) 163
|
||||
0, // empty(reserved) 164
|
||||
0, // empty(reserved) 165
|
||||
0, // empty(reserved) 166
|
||||
0, // empty(reserved) 167
|
||||
0, // empty(reserved) 168
|
||||
0, // empty(reserved) 169
|
||||
51, // job_skill(WOLFMAN SKILL) 170
|
||||
51, // job_skill(WOLFMAN SKILL) 171
|
||||
51, // job_skill(WOLFMAN SKILL) 172
|
||||
51, // job_skill(WOLFMAN SKILL) 173
|
||||
51, // job_skill(WOLFMAN SKILL) 174
|
||||
51, // job_skill(WOLFMAN SKILL) 175
|
||||
#endif
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
0, // job_skill(CONQUEROR SKILL) 176
|
||||
0, // job_skill(CONQUEROR SKILL) 177
|
||||
0, // job_skill(CONQUEROR SKILL) 178
|
||||
0, // job_skill(CONQUEROR SKILL) 179
|
||||
0, // job_skill(CONQUEROR SKILL) 180
|
||||
0, // job_skill(CONQUEROR SKILL) 181
|
||||
0, // job_skill(CONQUEROR SKILL) 182
|
||||
0, // job_skill(CONQUEROR SKILL) 183
|
||||
#endif
|
||||
}; // s_anSkill2JobGroup
|
||||
|
||||
const DWORD MOTION_MAX_NUM = 124;
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
const DWORD SKILL_LIST_MAX_COUNT = 6;
|
||||
#else
|
||||
const DWORD SKILL_LIST_MAX_COUNT = 5;
|
||||
#endif
|
||||
|
||||
static DWORD s_anMotion2SkillVnumList[MOTION_MAX_NUM][SKILL_LIST_MAX_COUNT] =
|
||||
{
|
||||
@@ -3189,18 +3387,31 @@ bool CHARACTER::IsUsableSkillMotion(DWORD dwMotionIndex) const
|
||||
{ 0, 0, 0, 0, 0 }, // 0
|
||||
|
||||
// 1번 직군 기본 스킬
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
{ 5, 1, 31, 61, 91, 170 }, // 1
|
||||
{ 5, 2, 32, 62, 92, 171 }, // 2
|
||||
{ 5, 3, 33, 63, 93, 172 }, // 3
|
||||
{ 5, 4, 34, 64, 94, 173 }, // 4
|
||||
{ 5, 5, 35, 65, 95, 174 }, // 5
|
||||
{ 5, 6, 36, 66, 96, 175 }, // 6
|
||||
#else
|
||||
{ 4, 1, 31, 61, 91 }, // 1
|
||||
{ 4, 2, 32, 62, 92 }, // 2
|
||||
{ 4, 3, 33, 63, 93 }, // 3
|
||||
{ 4, 4, 34, 64, 94 }, // 4
|
||||
{ 4, 5, 35, 65, 95 }, // 5
|
||||
{ 4, 6, 36, 66, 96 }, // 6
|
||||
#endif
|
||||
{ 0, 0, 0, 0, 0 }, // 7
|
||||
{ 0, 0, 0, 0, 0 }, // 8
|
||||
// 1번 직군 기본 스킬 끝
|
||||
|
||||
// 여유분
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
{ 5, 176, 177, 179, 181, 183 }, // 9
|
||||
#else
|
||||
{ 0, 0, 0, 0, 0 }, // 9
|
||||
#endif
|
||||
{ 0, 0, 0, 0, 0 }, // 10
|
||||
{ 0, 0, 0, 0, 0 }, // 11
|
||||
{ 0, 0, 0, 0, 0 }, // 12
|
||||
@@ -3221,23 +3432,40 @@ bool CHARACTER::IsUsableSkillMotion(DWORD dwMotionIndex) const
|
||||
// 2번 직군 기본 스킬 끝
|
||||
|
||||
// 여유분
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
{ 4, 176, 178, 180, 182 }, // 24
|
||||
#else
|
||||
{ 0, 0, 0, 0, 0 }, // 24
|
||||
#endif
|
||||
{ 0, 0, 0, 0, 0 }, // 25
|
||||
// 여유분 끝
|
||||
|
||||
// 1번 직군 마스터 스킬
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
{ 5, 1, 31, 61, 91, 170 }, // 26
|
||||
{ 5, 2, 32, 62, 92, 171 }, // 27
|
||||
{ 5, 3, 33, 63, 93, 172 }, // 28
|
||||
{ 5, 4, 34, 64, 94, 173 }, // 29
|
||||
{ 5, 5, 35, 65, 95, 174 }, // 30
|
||||
{ 5, 6, 36, 66, 96, 175 }, // 31
|
||||
#else
|
||||
{ 4, 1, 31, 61, 91 }, // 26
|
||||
{ 4, 2, 32, 62, 92 }, // 27
|
||||
{ 4, 3, 33, 63, 93 }, // 28
|
||||
{ 4, 4, 34, 64, 94 }, // 29
|
||||
{ 4, 5, 35, 65, 95 }, // 30
|
||||
{ 4, 6, 36, 66, 96 }, // 31
|
||||
#endif
|
||||
{ 0, 0, 0, 0, 0 }, // 32
|
||||
{ 0, 0, 0, 0, 0 }, // 33
|
||||
// 1번 직군 마스터 스킬 끝
|
||||
|
||||
// 여유분
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
{ 5, 176, 177, 179, 181, 183 }, // 34
|
||||
#else
|
||||
{ 0, 0, 0, 0, 0 }, // 34
|
||||
#endif
|
||||
{ 0, 0, 0, 0, 0 }, // 35
|
||||
{ 0, 0, 0, 0, 0 }, // 36
|
||||
{ 0, 0, 0, 0, 0 }, // 37
|
||||
@@ -3258,23 +3486,40 @@ bool CHARACTER::IsUsableSkillMotion(DWORD dwMotionIndex) const
|
||||
// 2번 직군 마스터 스킬 끝
|
||||
|
||||
// 여유분
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
{ 4, 176, 178, 180, 182 }, // 49
|
||||
#else
|
||||
{ 0, 0, 0, 0, 0 }, // 49
|
||||
#endif
|
||||
{ 0, 0, 0, 0, 0 }, // 50
|
||||
// 여유분 끝
|
||||
|
||||
// 1번 직군 그랜드 마스터 스킬
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
{ 5, 1, 31, 61, 91, 170 }, // 51
|
||||
{ 5, 2, 32, 62, 92, 171 }, // 52
|
||||
{ 5, 3, 33, 63, 93, 172 }, // 53
|
||||
{ 5, 4, 34, 64, 94, 173 }, // 54
|
||||
{ 5, 5, 35, 65, 95, 174 }, // 55
|
||||
{ 5, 6, 36, 66, 96, 175 }, // 56
|
||||
#else
|
||||
{ 4, 1, 31, 61, 91 }, // 51
|
||||
{ 4, 2, 32, 62, 92 }, // 52
|
||||
{ 4, 3, 33, 63, 93 }, // 53
|
||||
{ 4, 4, 34, 64, 94 }, // 54
|
||||
{ 4, 5, 35, 65, 95 }, // 55
|
||||
{ 4, 6, 36, 66, 96 }, // 56
|
||||
#endif
|
||||
{ 0, 0, 0, 0, 0 }, // 57
|
||||
{ 0, 0, 0, 0, 0 }, // 58
|
||||
// 1번 직군 그랜드 마스터 스킬 끝
|
||||
|
||||
// 여유분
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
{ 5, 176, 177, 179, 181, 183 }, // 59
|
||||
#else
|
||||
{ 0, 0, 0, 0, 0 }, // 59
|
||||
#endif
|
||||
{ 0, 0, 0, 0, 0 }, // 60
|
||||
{ 0, 0, 0, 0, 0 }, // 61
|
||||
{ 0, 0, 0, 0, 0 }, // 62
|
||||
@@ -3295,23 +3540,40 @@ bool CHARACTER::IsUsableSkillMotion(DWORD dwMotionIndex) const
|
||||
// 2번 직군 그랜드 마스터 스킬 끝
|
||||
|
||||
//여유분
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
{ 5, 176, 178, 180, 182, 183 }, // 74
|
||||
#else
|
||||
{ 0, 0, 0, 0, 0 }, // 74
|
||||
#endif
|
||||
{ 0, 0, 0, 0, 0 }, // 75
|
||||
// 여유분 끝
|
||||
|
||||
// 1번 직군 퍼펙트 마스터 스킬
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
{ 5, 1, 31, 61, 91, 170 }, // 76
|
||||
{ 5, 2, 32, 62, 92, 171 }, // 77
|
||||
{ 5, 3, 33, 63, 93, 172 }, // 78
|
||||
{ 5, 4, 34, 64, 94, 173 }, // 79
|
||||
{ 5, 5, 35, 65, 95, 174 }, // 80
|
||||
{ 5, 6, 36, 66, 96, 175 }, // 81
|
||||
#else
|
||||
{ 4, 1, 31, 61, 91 }, // 76
|
||||
{ 4, 2, 32, 62, 92 }, // 77
|
||||
{ 4, 3, 33, 63, 93 }, // 78
|
||||
{ 4, 4, 34, 64, 94 }, // 79
|
||||
{ 4, 5, 35, 65, 95 }, // 80
|
||||
{ 4, 6, 36, 66, 96 }, // 81
|
||||
#endif
|
||||
{ 0, 0, 0, 0, 0 }, // 82
|
||||
{ 0, 0, 0, 0, 0 }, // 83
|
||||
// 1번 직군 퍼펙트 마스터 스킬 끝
|
||||
|
||||
// 여유분
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
{ 5, 176, 177, 179, 181, 183 }, // 84
|
||||
#else
|
||||
{ 0, 0, 0, 0, 0 }, // 84
|
||||
#endif
|
||||
{ 0, 0, 0, 0, 0 }, // 85
|
||||
{ 0, 0, 0, 0, 0 }, // 86
|
||||
{ 0, 0, 0, 0, 0 }, // 87
|
||||
@@ -3332,7 +3594,11 @@ bool CHARACTER::IsUsableSkillMotion(DWORD dwMotionIndex) const
|
||||
// 2번 직군 퍼펙트 마스터 스킬 끝
|
||||
|
||||
// 여유분
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
{ 4, 176, 178, 180, 182 }, // 99
|
||||
#else
|
||||
{ 0, 0, 0, 0, 0 }, // 99
|
||||
#endif
|
||||
{ 0, 0, 0, 0, 0 }, // 100
|
||||
// 여유분 끝
|
||||
|
||||
@@ -3499,13 +3765,30 @@ bool CHARACTER::CanUseSkill(DWORD dwSkillVnum) const
|
||||
|
||||
if (0 < GetSkillGroup())
|
||||
{
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
const int SKILL_COUNT = 7;
|
||||
#else
|
||||
const int SKILL_COUNT = 6;
|
||||
#endif
|
||||
static const DWORD SkillList[JOB_MAX_NUM][SKILL_GROUP_MAX_NUM][SKILL_COUNT] =
|
||||
{
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
{ { 1, 2, 3, 4, 5, 6, 176 }, { 16, 17, 18, 19, 20, 21, 176 } },
|
||||
{ { 31, 32, 33, 34, 35, 36, 177 }, { 46, 47, 48, 49, 50, 51, 178 } },
|
||||
{ { 61, 62, 63, 64, 65, 66, 179 }, { 76, 77, 78, 79, 80, 81, 180 } },
|
||||
{ { 91, 92, 93, 94, 95, 96, 181 }, { 106,107,108,109,110,111,182 } },
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
{ { 170, 171, 172, 173, 174, 175, 183 }, { 0, 0, 0, 0, 0, 0, 0 } },
|
||||
#endif
|
||||
#else
|
||||
{ { 1, 2, 3, 4, 5, 6 }, { 16, 17, 18, 19, 20, 21 } },
|
||||
{ { 31, 32, 33, 34, 35, 36 }, { 46, 47, 48, 49, 50, 51 } },
|
||||
{ { 61, 62, 63, 64, 65, 66 }, { 76, 77, 78, 79, 80, 81 } },
|
||||
{ { 91, 92, 93, 94, 95, 96 }, { 106,107,108,109,110,111 } },
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
{ { 170, 171, 172, 173, 174, 175 }, { 0, 0, 0, 0, 0, 0 } },
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
const DWORD* pSkill = SkillList[ GetJob() ][ GetSkillGroup()-1 ];
|
||||
@@ -3587,6 +3870,9 @@ bool CHARACTER::CheckSkillHitCount(const BYTE SkillID, const VID TargetVID)
|
||||
{
|
||||
case SKILL_SAMYEON:
|
||||
case SKILL_CHARYUN:
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case SKILL_CHAYEOL:
|
||||
#endif
|
||||
MaxAttackCountPerTarget = 3;
|
||||
break;
|
||||
|
||||
|
||||
@@ -66,6 +66,9 @@ ACMD(do_who);
|
||||
ACMD(do_user);
|
||||
ACMD(do_disconnect);
|
||||
ACMD(do_kill);
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
ACMD(do_bleeding);
|
||||
#endif
|
||||
ACMD(do_emotion_allow);
|
||||
ACMD(do_emotion);
|
||||
ACMD(do_transfer);
|
||||
@@ -87,6 +90,9 @@ ACMD(do_console);
|
||||
ACMD(do_restart);
|
||||
ACMD(do_advance);
|
||||
ACMD(do_stat);
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
ACMD(do_conqueror_stat);
|
||||
#endif
|
||||
ACMD(do_respawn);
|
||||
ACMD(do_skillup);
|
||||
ACMD(do_guildskillup);
|
||||
@@ -305,6 +311,7 @@ ACMD (do_dragon_soul);
|
||||
ACMD (do_ds_list);
|
||||
ACMD (do_clear_affect);
|
||||
ACMD(do_gem);
|
||||
ACMD(do_won_exchange);
|
||||
ACMD(do_mt_economy);
|
||||
|
||||
ACMD(do_ishop);
|
||||
@@ -341,6 +348,9 @@ struct command_info cmd_info[] =
|
||||
{ "mc", do_mob_coward, 0, POS_DEAD, GM_HIGH_WIZARD },
|
||||
{ "mm", do_mob_map, 0, POS_DEAD, GM_HIGH_WIZARD },
|
||||
{ "kill", do_kill, 0, POS_DEAD, GM_HIGH_WIZARD },
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
{ "bleeding", do_bleeding, 0, POS_DEAD, GM_IMPLEMENTOR },
|
||||
#endif
|
||||
{ "ipurge", do_item_purge, 0, POS_DEAD, GM_HIGH_WIZARD },
|
||||
{ "group", do_group, 0, POS_DEAD, GM_HIGH_WIZARD },
|
||||
{ "grrandom", do_group_random, 0, POS_DEAD, GM_HIGH_WIZARD },
|
||||
@@ -357,6 +367,9 @@ struct command_info cmd_info[] =
|
||||
{ "shutdown", do_shutdown, 0, POS_DEAD, GM_HIGH_WIZARD },
|
||||
|
||||
{ "stat", do_stat, 0, POS_DEAD, GM_PLAYER },
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
{ "conqueror_stat", do_conqueror_stat, 0, POS_DEAD, GM_PLAYER },
|
||||
#endif
|
||||
{ "stat-", do_stat_minus, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "stat_reset", do_stat_reset, 0, POS_DEAD, GM_LOW_WIZARD },
|
||||
{ "state", do_state, 0, POS_DEAD, GM_LOW_WIZARD },
|
||||
@@ -655,6 +668,7 @@ struct command_info cmd_info[] =
|
||||
#endif
|
||||
{ "mt_economy", do_mt_economy, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "gem", do_gem, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "won_exchange", do_won_exchange, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "\n", NULL, 0, POS_DEAD, GM_IMPLEMENTOR } /* 반드시 이 것이 마지막이어야 한다. */
|
||||
};
|
||||
|
||||
|
||||
@@ -828,6 +828,54 @@ ACMD(do_stat)
|
||||
ch->ComputePoints();
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
// AVA2 conqueror stats: /conqueror_stat smh_str|smh_hp|smh_move|smh_inmune spends one conqueror point
|
||||
ACMD(do_conqueror_stat)
|
||||
{
|
||||
char arg1[256];
|
||||
one_argument(argument, arg1, sizeof(arg1));
|
||||
|
||||
if (!*arg1)
|
||||
return;
|
||||
|
||||
if (ch->IsPolymorphed())
|
||||
{
|
||||
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("둔갑 중에는 능력을 올릴 수 없습니다."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (ch->GetPoint(POINT_CONQUEROR_POINT) <= 0)
|
||||
return;
|
||||
|
||||
BYTE idx = 0;
|
||||
|
||||
if (!strcmp(arg1, "smh_str"))
|
||||
idx = POINT_SUNGMA_STR;
|
||||
else if (!strcmp(arg1, "smh_hp"))
|
||||
idx = POINT_SUNGMA_HP;
|
||||
else if (!strcmp(arg1, "smh_move"))
|
||||
idx = POINT_SUNGMA_MOVE;
|
||||
else if (!strcmp(arg1, "smh_inmune"))
|
||||
idx = POINT_SUNGMA_INMUNE;
|
||||
else
|
||||
return;
|
||||
|
||||
if (ch->GetRealPoint(idx) >= MAX_STAT)
|
||||
return;
|
||||
|
||||
ch->SetRealPoint(idx, ch->GetRealPoint(idx) + 1);
|
||||
ch->SetPoint(idx, ch->GetPoint(idx) + 1);
|
||||
ch->ComputePoints();
|
||||
ch->PointChange(idx, 0);
|
||||
|
||||
if (idx == POINT_SUNGMA_HP)
|
||||
ch->PointChange(POINT_MAX_HP, 0);
|
||||
|
||||
ch->PointChange(POINT_CONQUEROR_POINT, -1);
|
||||
ch->ComputePoints();
|
||||
}
|
||||
#endif
|
||||
|
||||
ACMD(do_pvp)
|
||||
{
|
||||
if (ch->GetArena() != NULL || CArenaManager::instance().IsArenaMap(ch->GetMapIndex()) == true)
|
||||
@@ -2007,6 +2055,9 @@ static const char* FN_point_string(int apply_number)
|
||||
case POINT_HP_REGEN: return LC_TEXT("생명력 회복 +%d");
|
||||
case POINT_SP_REGEN: return LC_TEXT("정신력 회복 +%d");
|
||||
case POINT_POISON_PCT: return LC_TEXT("독공격 %d");
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case POINT_BLEEDING_PCT: return LC_TEXT("독공격 %d");
|
||||
#endif
|
||||
case POINT_STUN_PCT: return LC_TEXT("스턴 +%d");
|
||||
case POINT_SLOW_PCT: return LC_TEXT("슬로우 +%d");
|
||||
case POINT_CRITICAL_PCT: return LC_TEXT("%d%% 확률로 치명타 공격");
|
||||
@@ -2031,6 +2082,9 @@ static const char* FN_point_string(int apply_number)
|
||||
case POINT_RESIST_BELL: return LC_TEXT("방울 방어 %d%%");
|
||||
case POINT_RESIST_FAN: return LC_TEXT("부채 방어 %d%%");
|
||||
case POINT_RESIST_BOW: return LC_TEXT("활공격 저항 %d%%");
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case POINT_RESIST_CLAW: return LC_TEXT("두손검 방어 %d%%");
|
||||
#endif
|
||||
case POINT_RESIST_FIRE: return LC_TEXT("화염 저항 %d%%");
|
||||
case POINT_RESIST_ELEC: return LC_TEXT("전기 저항 %d%%");
|
||||
case POINT_RESIST_MAGIC: return LC_TEXT("마법 저항 %d%%");
|
||||
@@ -2041,6 +2095,9 @@ static const char* FN_point_string(int apply_number)
|
||||
case POINT_REFLECT_MELEE: return LC_TEXT("직접 타격치 반사 확률 : %d%%");
|
||||
case POINT_REFLECT_CURSE: return LC_TEXT("저주 되돌리기 확률 %d%%");
|
||||
case POINT_POISON_REDUCE: return LC_TEXT("독 저항 %d%%");
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case POINT_BLEEDING_REDUCE: return LC_TEXT("독 저항 %d%%");
|
||||
#endif
|
||||
case POINT_KILL_SP_RECOVER: return LC_TEXT("%d%% 확률로 적퇴치시 정신력 회복");
|
||||
case POINT_EXP_DOUBLE_BONUS: return LC_TEXT("%d%% 확률로 적퇴치시 경험치 추가 상승");
|
||||
case POINT_GOLD_DOUBLE_BONUS: return LC_TEXT("%d%% 확률로 적퇴치시 돈 2배 드롭");
|
||||
@@ -2062,6 +2119,9 @@ static const char* FN_point_string(int apply_number)
|
||||
case POINT_ATTBONUS_ASSASSIN: return LC_TEXT("자객에게 강함 +%d%%");
|
||||
case POINT_ATTBONUS_SURA: return LC_TEXT("수라에게 강함 +%d%%");
|
||||
case POINT_ATTBONUS_SHAMAN: return LC_TEXT("무당에게 강함 +%d%%");
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case POINT_ATTBONUS_WOLFMAN: return LC_TEXT("무당에게 강함 +%d%%");
|
||||
#endif
|
||||
case POINT_ATTBONUS_MONSTER: return LC_TEXT("몬스터에게 강함 +%d%%");
|
||||
case POINT_MALL_ATTBONUS: return LC_TEXT("공격력 +%d%%");
|
||||
case POINT_MALL_DEFBONUS: return LC_TEXT("방어력 +%d%%");
|
||||
@@ -2081,6 +2141,9 @@ static const char* FN_point_string(int apply_number)
|
||||
case POINT_RESIST_ASSASSIN: return LC_TEXT("자객공격에 %d%% 저항");
|
||||
case POINT_RESIST_SURA: return LC_TEXT("수라공격에 %d%% 저항");
|
||||
case POINT_RESIST_SHAMAN: return LC_TEXT("무당공격에 %d%% 저항");
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case POINT_RESIST_WOLFMAN: return LC_TEXT("무당공격에 %d%% 저항");
|
||||
#endif
|
||||
default: return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1023,18 +1023,34 @@ ACMD(do_state)
|
||||
tch->GetPoint(POINT_DODGE),
|
||||
tch->GetPoint(POINT_DEF_BONUS));
|
||||
ch->ChatPacket(CHAT_TYPE_INFO, "RESISTANCES:");
|
||||
ch->ChatPacket(CHAT_TYPE_INFO, " WARR:%3d%% ASAS:%3d%% SURA:%3d%% SHAM:%3d%%",
|
||||
ch->ChatPacket(CHAT_TYPE_INFO, " WARR:%3d%% ASAS:%3d%% SURA:%3d%% SHAM:%3d%%"
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
" WOLF:%3d%%"
|
||||
#endif
|
||||
,
|
||||
tch->GetPoint(POINT_RESIST_WARRIOR),
|
||||
tch->GetPoint(POINT_RESIST_ASSASSIN),
|
||||
tch->GetPoint(POINT_RESIST_SURA),
|
||||
tch->GetPoint(POINT_RESIST_SHAMAN));
|
||||
ch->ChatPacket(CHAT_TYPE_INFO, " SWORD:%3d%% THSWORD:%3d%% DAGGER:%3d%% BELL:%3d%% FAN:%3d%% BOW:%3d%%",
|
||||
tch->GetPoint(POINT_RESIST_SHAMAN)
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
,tch->GetPoint(POINT_RESIST_WOLFMAN)
|
||||
#endif
|
||||
);
|
||||
ch->ChatPacket(CHAT_TYPE_INFO, " SWORD:%3d%% THSWORD:%3d%% DAGGER:%3d%% BELL:%3d%% FAN:%3d%% BOW:%3d%%"
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
" CLAW:%3d%%"
|
||||
#endif
|
||||
,
|
||||
tch->GetPoint(POINT_RESIST_SWORD),
|
||||
tch->GetPoint(POINT_RESIST_TWOHAND),
|
||||
tch->GetPoint(POINT_RESIST_DAGGER),
|
||||
tch->GetPoint(POINT_RESIST_BELL),
|
||||
tch->GetPoint(POINT_RESIST_FAN),
|
||||
tch->GetPoint(POINT_RESIST_BOW));
|
||||
tch->GetPoint(POINT_RESIST_BOW)
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
,tch->GetPoint(POINT_RESIST_CLAW)
|
||||
#endif
|
||||
);
|
||||
ch->ChatPacket(CHAT_TYPE_INFO, " FIRE:%3d%% ELEC:%3d%% MAGIC:%3d%% WIND:%3d%% CRIT:%3d%% PENE:%3d%%",
|
||||
tch->GetPoint(POINT_RESIST_FIRE),
|
||||
tch->GetPoint(POINT_RESIST_ELEC),
|
||||
@@ -1080,11 +1096,19 @@ ACMD(do_state)
|
||||
tch->GetPoint(POINT_ATTBONUS_TREE),
|
||||
tch->GetPoint(POINT_ATTBONUS_MONSTER));
|
||||
|
||||
ch->ChatPacket(CHAT_TYPE_INFO, " WARR:%3d%% ASAS:%3d%% SURA:%3d%% SHAM:%3d%%",
|
||||
ch->ChatPacket(CHAT_TYPE_INFO, " WARR:%3d%% ASAS:%3d%% SURA:%3d%% SHAM:%3d%%"
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
" WOLF:%3d%%"
|
||||
#endif
|
||||
,
|
||||
tch->GetPoint(POINT_ATTBONUS_WARRIOR),
|
||||
tch->GetPoint(POINT_ATTBONUS_ASSASSIN),
|
||||
tch->GetPoint(POINT_ATTBONUS_SURA),
|
||||
tch->GetPoint(POINT_ATTBONUS_SHAMAN));
|
||||
tch->GetPoint(POINT_ATTBONUS_SHAMAN)
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
,tch->GetPoint(POINT_ATTBONUS_WOLFMAN)
|
||||
#endif
|
||||
);
|
||||
|
||||
for (int i = 0; i < MAX_PRIV_NUM; ++i)
|
||||
if (CPrivManager::instance().GetPriv(tch, i))
|
||||
@@ -1392,6 +1416,30 @@ ACMD(do_kill)
|
||||
tch->Dead();
|
||||
}
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
ACMD(do_bleeding)
|
||||
{
|
||||
char arg1[256];
|
||||
one_argument(argument, arg1, sizeof(arg1));
|
||||
|
||||
if (!*arg1)
|
||||
{
|
||||
ch->ChatPacket(CHAT_TYPE_INFO, "ex) /bleeding <player name>");
|
||||
return;
|
||||
}
|
||||
|
||||
LPDESC d = DESC_MANAGER::instance().FindByCharacterName(arg1);
|
||||
LPCHARACTER tch = d ? d->GetCharacter() : NULL;
|
||||
|
||||
if (!tch)
|
||||
{
|
||||
ch->ChatPacket(CHAT_TYPE_INFO, "%s: no such a player", arg1);
|
||||
return;
|
||||
}
|
||||
|
||||
tch->AttackedByBleeding(NULL);
|
||||
}
|
||||
#endif
|
||||
#define MISC 0
|
||||
#define BINARY 1
|
||||
#define NUMBER 2
|
||||
@@ -4242,6 +4290,37 @@ ACMD (do_item_full_set)
|
||||
M2_DESTROY_ITEM(item);
|
||||
}
|
||||
break;
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case JOB_WOLFMAN:
|
||||
{
|
||||
|
||||
item = ITEM_MANAGER::instance().CreateItem(21049);
|
||||
if (!item || !item->EquipTo(ch, item->FindEquipCell(ch)))
|
||||
M2_DESTROY_ITEM(item);
|
||||
item = ITEM_MANAGER::instance().CreateItem(13049);
|
||||
if (!item || !item->EquipTo(ch, item->FindEquipCell(ch)))
|
||||
M2_DESTROY_ITEM(item);
|
||||
item = ITEM_MANAGER::instance().CreateItem(15189);
|
||||
if (!item || !item->EquipTo(ch, item->FindEquipCell(ch)))
|
||||
M2_DESTROY_ITEM(item);
|
||||
item = ITEM_MANAGER::instance().CreateItem(6049);
|
||||
if (!item || !item->EquipTo(ch, item->FindEquipCell(ch)))
|
||||
M2_DESTROY_ITEM(item);
|
||||
item = ITEM_MANAGER::instance().CreateItem(21559);
|
||||
if (!item || !item->EquipTo(ch, item->FindEquipCell(ch)))
|
||||
M2_DESTROY_ITEM(item);
|
||||
item = ITEM_MANAGER::instance().CreateItem(14109);
|
||||
if (!item || !item->EquipTo(ch, item->FindEquipCell(ch)))
|
||||
M2_DESTROY_ITEM(item);
|
||||
item = ITEM_MANAGER::instance().CreateItem(17209);
|
||||
if (!item || !item->EquipTo(ch, item->FindEquipCell(ch)))
|
||||
M2_DESTROY_ITEM(item);
|
||||
item = ITEM_MANAGER::instance().CreateItem(16209);
|
||||
if (!item || !item->EquipTo(ch, item->FindEquipCell(ch)))
|
||||
M2_DESTROY_ITEM(item);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4256,6 +4335,9 @@ ACMD (do_attr_full_set)
|
||||
case JOB_ASSASSIN:
|
||||
case JOB_SURA:
|
||||
case JOB_SHAMAN:
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case JOB_WOLFMAN:
|
||||
#endif
|
||||
{
|
||||
// 무사 몸빵 셋팅.
|
||||
// 이것만 나와 있어서 임시로 모든 직군 다 이런 속성 따름.
|
||||
|
||||
@@ -133,6 +133,9 @@ bool g_noticeBattleZone = false; //
|
||||
// bool bXTrapEnabled = false;
|
||||
|
||||
int gPlayerMaxLevel = 99;
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
int gPlayerConquerorMaxLevel = 30;
|
||||
#endif
|
||||
|
||||
bool g_BlockCharCreation = false;
|
||||
|
||||
@@ -1142,6 +1145,17 @@ void config_init(const string& st_localeServiceName)
|
||||
fprintf(stderr, "PLAYER_MAX_LEVEL: %d\n", gPlayerMaxLevel);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
TOKEN("max_conqueror_level")
|
||||
{
|
||||
str_to_number(gPlayerConquerorMaxLevel, value_string);
|
||||
|
||||
gPlayerConquerorMaxLevel = MINMAX(1, gPlayerConquerorMaxLevel, PLAYER_MAX_CONQUEROR_LEVEL_CONST);
|
||||
|
||||
fprintf(stderr, "PLAYER_CONQUEROR_MAX_LEVEL: %d\n", gPlayerConquerorMaxLevel);
|
||||
}
|
||||
#endif
|
||||
|
||||
TOKEN("block_char_creation")
|
||||
{
|
||||
int tmp = 0;
|
||||
|
||||
@@ -118,6 +118,9 @@ extern DWORD g_GoldDropTimeLimitValue;
|
||||
// extern bool bXTrapEnabled;
|
||||
|
||||
extern int gPlayerMaxLevel;
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
extern int gPlayerConquerorMaxLevel;
|
||||
#endif
|
||||
|
||||
extern bool g_BlockCharCreation;
|
||||
|
||||
|
||||
@@ -18,7 +18,10 @@ TJobInitialPoints JobInitialPoints[JOB_MAX_NUM] =
|
||||
{ 6, 4, 3, 3, 600, 200, 40, 20, 36, 44, 18, 22, 800, 5, 1, 3 }, // JOB_WARRIOR 16
|
||||
{ 4, 3, 6, 3, 650, 200, 40, 20, 36, 44, 18, 22, 800, 5, 1, 3 }, // JOB_ASSASSIN 16
|
||||
{ 5, 3, 3, 5, 650, 200, 40, 20, 36, 44, 18, 22, 800, 5, 1, 3 }, // JOB_SURA 16
|
||||
{ 3, 4, 3, 6, 700, 200, 40, 20, 36, 44, 18, 22, 800, 5, 1, 3 } // JOB_SHAMANa 16
|
||||
{ 3, 4, 3, 6, 700, 200, 40, 20, 36, 44, 18, 22, 800, 5, 1, 3 }, // JOB_SHAMANa 16
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
{ 2, 6, 6, 2, 600, 200, 40, 20, 36, 44, 18, 22, 800, 5, 1, 3 }, // JOB_WOLFMAN 16 // TODO: 4개능력치 초기값 외에 다른 스탯 필요 (기획자한테 요청)
|
||||
#endif
|
||||
};
|
||||
|
||||
const TMobRankStat MobRankStats[MOB_RANK_MAX_NUM] =
|
||||
@@ -186,6 +189,44 @@ const DWORD exp_table_euckr[PLAYER_EXP_TABLE_MAX + 1] =
|
||||
2100000000, // 120
|
||||
};
|
||||
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
// AVA2 conqueror (Yohara) exp table: index = conqueror level
|
||||
const DWORD exp_coqueror_table[PLAYER_MAX_CONQUEROR_LEVEL_CONST + 1] =
|
||||
{
|
||||
0, // 0
|
||||
433400, // 1
|
||||
1300204, // 2
|
||||
2600413, // 3
|
||||
4334029, // 4
|
||||
6501054, // 5
|
||||
9101490, // 6
|
||||
12135339, // 7
|
||||
15602603, // 8
|
||||
19503284, // 9
|
||||
23837384, // 10
|
||||
28604905, // 11
|
||||
33805849, // 12
|
||||
39440218, // 13
|
||||
45508014, // 14
|
||||
52009239, // 15
|
||||
58943895, // 16
|
||||
66311984, // 17
|
||||
74113508, // 18
|
||||
82348469, // 19
|
||||
91016869, // 20
|
||||
100118710, // 21
|
||||
109653994, // 22
|
||||
119622723, // 23
|
||||
130024899, // 24
|
||||
140860524, // 25
|
||||
152129600, // 26
|
||||
163832129, // 27
|
||||
175968113, // 28
|
||||
188537554, // 29
|
||||
188537554, // 30
|
||||
};
|
||||
#endif
|
||||
|
||||
const DWORD exp_table_common[PLAYER_EXP_TABLE_MAX + 1] =
|
||||
{
|
||||
0, // 0
|
||||
@@ -755,6 +796,9 @@ const int aiMobEnchantApplyIdx[MOB_ENCHANTS_MAX_NUM] =
|
||||
APPLY_STUN_PCT,
|
||||
APPLY_CRITICAL_PCT,
|
||||
APPLY_PENETRATE_PCT,
|
||||
#if defined(ENABLE_WOLFMAN_CHARACTER) && !defined(USE_MOB_BLEEDING_AS_POISON)
|
||||
APPLY_BLEEDING_PCT,
|
||||
#endif
|
||||
};
|
||||
|
||||
const int aiMobResistsApplyIdx[MOB_RESISTS_MAX_NUM] =
|
||||
@@ -770,6 +814,12 @@ const int aiMobResistsApplyIdx[MOB_RESISTS_MAX_NUM] =
|
||||
APPLY_RESIST_MAGIC,
|
||||
APPLY_RESIST_WIND,
|
||||
APPLY_POISON_REDUCE,
|
||||
#if defined(ENABLE_WOLFMAN_CHARACTER) && !defined(USE_MOB_BLEEDING_AS_POISON)
|
||||
APPLY_BLEEDING_REDUCE,
|
||||
#endif
|
||||
#if defined(ENABLE_WOLFMAN_CHARACTER) && !defined(USE_MOB_CLAW_AS_DAGGER)
|
||||
APPLY_RESIST_CLAW,
|
||||
#endif
|
||||
};
|
||||
|
||||
const int aiSocketPercentByQty[5][4] =
|
||||
@@ -791,6 +841,8 @@ const int aiWeaponSocketQty[WEAPON_NUM_TYPES] =
|
||||
3, // WEAPON_FAN,
|
||||
0, // WEAPON_ARROW,
|
||||
0, // WEAPON_MOUNT_SPEAR
|
||||
3, // WEAPON_CLAW (numeric reservation)
|
||||
0, // WEAPON_QUIVER
|
||||
};
|
||||
|
||||
const int aiArmorSocketQty[ARMOR_NUM_TYPES] =
|
||||
@@ -915,11 +967,19 @@ const TApplyInfo aApplyInfo[MAX_APPLY_NUM] =
|
||||
{ POINT_RESIST_CRITICAL, }, // APPLY_ANTI_CRITICAL_PCT, 90
|
||||
{ POINT_RESIST_PENETRATE, }, // APPLY_ANTI_PENETRATE_PCT, 91
|
||||
// PORT AVA2 applies 92-138, not ported yet
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
{ POINT_BLEEDING_REDUCE, }, // APPLY_BLEEDING_REDUCE, 92
|
||||
{ POINT_BLEEDING_PCT, }, // APPLY_BLEEDING_PCT, 93
|
||||
{ POINT_ATTBONUS_WOLFMAN, }, // APPLY_ATTBONUS_WOLFMAN, 94
|
||||
{ POINT_RESIST_WOLFMAN, }, // APPLY_RESIST_WOLFMAN, 95
|
||||
{ POINT_RESIST_CLAW, }, // APPLY_RESIST_CLAW, 96
|
||||
#else
|
||||
{ POINT_NONE }, // 92
|
||||
{ POINT_NONE }, // 93
|
||||
{ POINT_NONE }, // 94
|
||||
{ POINT_NONE }, // 95
|
||||
{ POINT_NONE }, // 96
|
||||
#endif
|
||||
{ POINT_NONE }, // 97
|
||||
{ POINT_RESIST_MAGIC_REDUCTION }, // APPLY_RESIST_MAGIC_REDUCTION 98
|
||||
{ POINT_RESIST_HUMAN }, // APPLY_RESIST_HUMAN 99
|
||||
@@ -942,10 +1002,17 @@ const TApplyInfo aApplyInfo[MAX_APPLY_NUM] =
|
||||
{ POINT_NONE }, // 116
|
||||
{ POINT_NONE }, // 117
|
||||
{ POINT_NONE }, // 118
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
{ POINT_SUNGMA_STR }, // APPLY_SUNGMA_STR 119
|
||||
{ POINT_SUNGMA_HP }, // APPLY_SUNGMA_HP 120
|
||||
{ POINT_SUNGMA_MOVE }, // APPLY_SUNGMA_MOVE 121
|
||||
{ POINT_SUNGMA_INMUNE }, // APPLY_SUNGMA_INMUNE 122
|
||||
#else
|
||||
{ POINT_NONE }, // 119
|
||||
{ POINT_NONE }, // 120
|
||||
{ POINT_NONE }, // 121
|
||||
{ POINT_NONE }, // 122
|
||||
#endif
|
||||
{ POINT_ENCHANT_ELEC }, // APPLY_ENCHANT_ELEC 123
|
||||
{ POINT_ENCHANT_FIRE }, // APPLY_ENCHANT_FIRE 124
|
||||
{ POINT_ENCHANT_ICE }, // APPLY_ENCHANT_ICE 125
|
||||
@@ -961,7 +1028,11 @@ const TApplyInfo aApplyInfo[MAX_APPLY_NUM] =
|
||||
{ POINT_NONE }, // 135
|
||||
{ POINT_NONE }, // 136
|
||||
{ POINT_NONE }, // 137
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
{ POINT_ATTBONUS_CLAW }, // APPLY_ATTBONUS_CLAW 138
|
||||
#else
|
||||
{ POINT_NONE }, // 138
|
||||
#endif
|
||||
{ POINT_ATTBONUS_STONE }, // APPLY_ATTBONUS_STONE 139
|
||||
{ POINT_ATTBONUS_BOSS }, // APPLY_ATTBONUS_BOSS 140
|
||||
};
|
||||
@@ -1332,9 +1403,22 @@ TValueName c_aApplyTypeNames[] =
|
||||
{ "MELEE_MAGIC_ATTBONUS_PER", APPLY_MELEE_MAGIC_ATTBONUS_PER },
|
||||
|
||||
{ "RESIST_HUMAN", APPLY_RESIST_HUMAN },
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
{ "BLEEDING_REDUCE",APPLY_BLEEDING_REDUCE },
|
||||
{ "BLEEDING_PCT",APPLY_BLEEDING_PCT },
|
||||
{ "ATT_BONUS_TO_WOLFMAN",APPLY_ATTBONUS_WOLFMAN },
|
||||
{ "RESIST_WOLFMAN",APPLY_RESIST_WOLFMAN },
|
||||
{ "RESIST_CLAW",APPLY_RESIST_CLAW },
|
||||
#endif
|
||||
{ "RESIST_MAGIC_REDUCTION", APPLY_RESIST_MAGIC_REDUCTION },
|
||||
{ "ATTBONUS_STONE", APPLY_ATTBONUS_STONE },
|
||||
{ "ATTBONUS_BOSS", APPLY_ATTBONUS_BOSS },
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
{ "SUNGMA_STR", APPLY_SUNGMA_STR },
|
||||
{ "SUNGMA_HP", APPLY_SUNGMA_HP },
|
||||
{ "SUNGMA_MOVE", APPLY_SUNGMA_MOVE },
|
||||
{ "SUNGMA_INMUNE", APPLY_SUNGMA_INMUNE },
|
||||
#endif
|
||||
{ "ENCHANT_ELEC", APPLY_ENCHANT_ELEC },
|
||||
{ "ENCHANT_FIRE", APPLY_ENCHANT_FIRE },
|
||||
{ "ENCHANT_ICE", APPLY_ENCHANT_ICE },
|
||||
|
||||
@@ -96,6 +96,9 @@ extern const TMobRankStat MobRankStats[MOB_RANK_MAX_NUM];
|
||||
extern TBattleTypeStat BattleTypeStats[BATTLE_TYPE_MAX_NUM];
|
||||
|
||||
extern const DWORD party_exp_distribute_table[PLAYER_MAX_LEVEL_CONST + 1];
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
extern const DWORD exp_coqueror_table[PLAYER_MAX_CONQUEROR_LEVEL_CONST + 1];
|
||||
#endif
|
||||
|
||||
extern const DWORD exp_table_euckr[PLAYER_EXP_TABLE_MAX + 1];
|
||||
extern const DWORD exp_table_common[PLAYER_EXP_TABLE_MAX + 1];
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#define _cube_cpp_
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "port_material_stack_policy.h"
|
||||
#include "port_cube_actor.h"
|
||||
#include "constants.h"
|
||||
#include "utils.h"
|
||||
#include "log.h"
|
||||
@@ -332,6 +334,11 @@ void Cube_open (LPCHARACTER ch)
|
||||
|
||||
|
||||
Cube_clean_item(ch);
|
||||
if (CubeRenewal_ClientSupported(ch))
|
||||
{
|
||||
CubeRenewal_Open(ch, npc);
|
||||
return;
|
||||
}
|
||||
ch->SetCubeNpc(npc);
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND, "cube open %d", npc->GetRaceNum());
|
||||
}
|
||||
@@ -363,6 +370,7 @@ void Cube_init()
|
||||
}
|
||||
|
||||
s_cube_proto.clear();
|
||||
PortMaterialStackPolicy::CubeIngredients().clear();
|
||||
|
||||
if (false == Cube_load(file_name))
|
||||
sys_err("Cube_Init failed");
|
||||
@@ -397,8 +405,11 @@ bool Cube_load (const char *file)
|
||||
continue;
|
||||
|
||||
// set value1, value2
|
||||
if ((v = strtok(NULL, delim)))
|
||||
const char* port_value = NULL;
|
||||
if ((v = strtok(NULL, delim))) {
|
||||
port_value = v;
|
||||
str_to_number(value1, v);
|
||||
}
|
||||
|
||||
if ((v = strtok(NULL, delim)))
|
||||
str_to_number(value2, v);
|
||||
@@ -429,6 +440,14 @@ bool Cube_load (const char *file)
|
||||
{
|
||||
cube_data->percent = value1;
|
||||
}
|
||||
else TOKEN("category")
|
||||
{
|
||||
cube_data->portCategory = port_value ? port_value : "";
|
||||
}
|
||||
else TOKEN("copy")
|
||||
{
|
||||
cube_data->portCopy = value1 > 0;
|
||||
}
|
||||
else TOKEN("gold")
|
||||
{
|
||||
// 제조에 필요한 금액
|
||||
@@ -444,6 +463,8 @@ bool Cube_load (const char *file)
|
||||
continue;
|
||||
}
|
||||
s_cube_proto.push_back(cube_data);
|
||||
for (const auto& material : cube_data->item)
|
||||
PortMaterialStackPolicy::CubeIngredients().insert(material.vnum);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -509,6 +530,7 @@ static bool FN_update_cube_status(LPCHARACTER ch)
|
||||
// return new item
|
||||
bool Cube_make (LPCHARACTER ch)
|
||||
{
|
||||
if(PortCubeActorHeld(ch))return false;
|
||||
// 주어진 아이템을 필요로하는 조합을 찾는다. (큐브데이타로 칭함)
|
||||
// 큐브 데이타가 있다면 아이템의 재료를 체크한다.
|
||||
// 새로운 아이템을 만든다.
|
||||
@@ -980,3 +1002,7 @@ void Cube_request_material_info(LPCHARACTER ch, int requestStartIndex, int reque
|
||||
|
||||
|
||||
}
|
||||
|
||||
// PORT: current loaded Cube catalogue and read-only batch preflight.
|
||||
#include "port_cube_catalog.inc"
|
||||
#include "port_cube_renewal.inc"
|
||||
|
||||
@@ -31,6 +31,8 @@ struct CUBE_DATA
|
||||
std::vector<CUBE_VALUE> reward;
|
||||
int percent;
|
||||
unsigned int gold; // 제조시 필요한 금액
|
||||
std::string portCategory = "WORLDARD";
|
||||
bool portCopy = false;
|
||||
|
||||
CUBE_DATA();
|
||||
|
||||
@@ -61,5 +63,11 @@ void Cube_print();
|
||||
|
||||
bool Cube_InformationInitialize();
|
||||
|
||||
// AVA2 cuberenewal (port_cube_renewal.inc): same cube.txt recipes, native window.
|
||||
bool CubeRenewal_ClientSupported(LPCHARACTER ch);
|
||||
void CubeRenewal_Open(LPCHARACTER ch, LPCHARACTER npc);
|
||||
void CubeRenewal_Make(LPCHARACTER ch, DWORD index, DWORD count);
|
||||
void CubeRenewal_Close(LPCHARACTER ch);
|
||||
|
||||
#endif /* _cube_h_ */
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "event_queue.h"
|
||||
#include <memory>
|
||||
|
||||
extern void ContinueOnFatalError();
|
||||
extern void ShutdownOnFatalError();
|
||||
@@ -21,6 +22,8 @@ static CEventQueue cxx_q;
|
||||
/* 이벤트를 생성하고 리턴한다 */
|
||||
LPEVENT event_create_ex(TEVENTFUNC func, event_info_data* info, long when)
|
||||
{
|
||||
// PORT: ownership starts on entry, including event/node allocation failure.
|
||||
std::unique_ptr<event_info_data> pendingInfo(info);
|
||||
LPEVENT new_event = NULL;
|
||||
|
||||
/* 반드시 다음 pulse 이상의 시간이 지난 후에 부르도록 한다. */
|
||||
@@ -36,7 +39,7 @@ LPEVENT event_create_ex(TEVENTFUNC func, event_info_data* info, long when)
|
||||
assert(NULL != new_event);
|
||||
|
||||
new_event->func = func;
|
||||
new_event->info = info;
|
||||
new_event->info = pendingInfo.release();
|
||||
new_event->q_el = cxx_q.Enqueue(new_event, when, thecore_heart->pulse);
|
||||
new_event->is_processing = FALSE;
|
||||
new_event->is_force_to_end = FALSE;
|
||||
@@ -120,6 +123,9 @@ int event_process(int pulse)
|
||||
|
||||
LPEVENT the_event = pElem->pvData;
|
||||
long processing_time = event_processing_time(the_event);
|
||||
// The callback may cancel itself while destroying its owning item.
|
||||
// Detach the dequeued node before Delete makes that pointer invalid.
|
||||
the_event->q_el = NULL;
|
||||
cxx_q.Delete(pElem);
|
||||
|
||||
/*
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "event_queue.h"
|
||||
#include <memory>
|
||||
|
||||
CEventQueue::CEventQueue()
|
||||
{
|
||||
@@ -41,7 +42,17 @@ TQueueElement * CEventQueue::Enqueue(LPEVENT pvData, int duration, int pulse)
|
||||
pElem->iKey = duration + pulse;
|
||||
pElem->bCancel = FALSE;
|
||||
|
||||
// PORT: vector insertion may throw. Do not leak the node/event reference.
|
||||
auto discard=[&](TQueueElement* node){
|
||||
#ifdef M2_USE_POOL
|
||||
pool_.Destroy(node);
|
||||
#else
|
||||
M2_DELETE(node);
|
||||
#endif
|
||||
};
|
||||
std::unique_ptr<TQueueElement,decltype(discard)> pending(pElem,discard);
|
||||
m_pq_queue.push(pElem);
|
||||
pending.release();
|
||||
return pElem;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "../../common/length.h"
|
||||
#include "exchange.h"
|
||||
#include "DragonSoul.h"
|
||||
#include "port_cheque.h"
|
||||
|
||||
void exchange_packet(LPCHARACTER ch, BYTE sub_header, bool is_me, int64_t arg1, TItemPos arg2, DWORD arg3, void * pvData = NULL);
|
||||
|
||||
@@ -104,8 +105,8 @@ bool CHARACTER::ExchangeStart(LPCHARACTER victim)
|
||||
SetExchangeTime();
|
||||
victim->SetExchangeTime();
|
||||
|
||||
exchange_packet(victim, EXCHANGE_SUBHEADER_GC_START, 0, GetVID(), NPOS, 0);
|
||||
exchange_packet(this, EXCHANGE_SUBHEADER_GC_START, 0, victim->GetVID(), NPOS, 0);
|
||||
exchange_packet(victim, EXCHANGE_SUBHEADER_GC_START, 0, GetVID(), NPOS, GetLevel());
|
||||
exchange_packet(this, EXCHANGE_SUBHEADER_GC_START, 0, victim->GetVID(), NPOS, victim->GetLevel());
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -124,6 +125,7 @@ CExchange::CExchange(LPCHARACTER pOwner)
|
||||
}
|
||||
|
||||
m_lGold = 0;
|
||||
m_lCheque = 0;
|
||||
|
||||
m_pOwner = pOwner;
|
||||
pOwner->SetExchange(this);
|
||||
@@ -275,6 +277,35 @@ bool CExchange::AddGold(int64_t gold)
|
||||
return true;
|
||||
}
|
||||
|
||||
// PORT: Won offer; both sides need a Won-aware client (an old one would never see it).
|
||||
bool CExchange::AddCheque(int64_t cheque)
|
||||
{
|
||||
LPCHARACTER victim = GetCompany()->GetOwner();
|
||||
if (cheque <= 0 || cheque > CHEQUE_MAX || !PortChequeClientSupported(GetOwner()) || !PortChequeClientSupported(victim))
|
||||
return false;
|
||||
|
||||
if (PortChequeGet(GetOwner()) < cheque)
|
||||
{
|
||||
exchange_packet(GetOwner(), EXCHANGE_SUBHEADER_GC_LESS_CHEQUE, 0, 0, NPOS, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!PortChequeCanChange(victim, cheque))
|
||||
{
|
||||
GetOwner()->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("The other player can't carry more Won."));
|
||||
return false;
|
||||
}
|
||||
|
||||
Accept(false);
|
||||
GetCompany()->Accept(false);
|
||||
|
||||
m_lCheque = cheque;
|
||||
|
||||
exchange_packet(GetOwner(), EXCHANGE_SUBHEADER_GC_CHEQUE_ADD, true, m_lCheque, NPOS, 0);
|
||||
exchange_packet(victim, EXCHANGE_SUBHEADER_GC_CHEQUE_ADD, false, m_lCheque, NPOS, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 돈이 충분히 있는지, 교환하려는 아이템이 실제로 있는지 확인 한다.
|
||||
bool CExchange::Check(int * piItemCount)
|
||||
{
|
||||
@@ -285,6 +316,11 @@ bool CExchange::Check(int * piItemCount)
|
||||
if (m_lGold > 0 && victim->GetGold() > GOLD_MAX_64 - m_lGold)
|
||||
return false;
|
||||
|
||||
// Won settles as one net transfer in Accept, so bound the victim's final balance.
|
||||
if (m_lCheque > 0 && (PortChequeGet(GetOwner()) < m_lCheque ||
|
||||
!PortChequeCanChange(victim, m_lCheque - GetCompany()->m_lCheque)))
|
||||
return false;
|
||||
|
||||
int item_count = 0;
|
||||
|
||||
for (int i = 0; i < EXCHANGE_ITEM_MAX_NUM; ++i)
|
||||
@@ -616,12 +652,21 @@ bool CExchange::Accept(bool bAccept)
|
||||
|
||||
if (Done())
|
||||
{
|
||||
if (m_lGold) // µ·ÀÌ ÀÖÀ» ‹š¸¸ ÀúÀå
|
||||
const int64_t netCheque = m_lCheque - GetCompany()->m_lCheque;
|
||||
if (netCheque)
|
||||
{
|
||||
PortChequeChange(GetOwner(), -netCheque);
|
||||
PortChequeChange(victim, netCheque);
|
||||
LogManager::instance().CharLog(victim, netCheque, "EXCHANGE_CHEQUE_TAKE", GetOwner()->GetName());
|
||||
LogManager::instance().CharLog(GetOwner(), -netCheque, "EXCHANGE_CHEQUE_GIVE", victim->GetName());
|
||||
}
|
||||
|
||||
if (m_lGold || netCheque) // µ·ÀÌ ÀÖÀ» ‹š¸¸ ÀúÀå
|
||||
GetOwner()->Save();
|
||||
|
||||
if (GetCompany()->Done())
|
||||
{
|
||||
if (GetCompany()->m_lGold) // µ·ÀÌ ÀÖÀ» ¶§¸¸ ÀúÀå
|
||||
if (GetCompany()->m_lGold || netCheque) // µ·ÀÌ ÀÖÀ» ¶§¸¸ ÀúÀå
|
||||
victim->Save();
|
||||
|
||||
// INTERNATIONAL_VERSION
|
||||
|
||||
@@ -19,6 +19,7 @@ class CExchange
|
||||
void Cancel();
|
||||
|
||||
bool AddGold(int64_t lGold);
|
||||
bool AddCheque(int64_t lCheque);
|
||||
bool AddItem(TItemPos item_pos, BYTE display_pos);
|
||||
bool RemoveItem(BYTE pos);
|
||||
|
||||
@@ -54,6 +55,7 @@ class CExchange
|
||||
|
||||
bool m_bAccept;
|
||||
int64_t m_lGold;
|
||||
int64_t m_lCheque;
|
||||
|
||||
CGrid * m_pGrid;
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#include "stdafx.h"
|
||||
#include "ava2_itemshop.h"
|
||||
#include "port_economy.h"
|
||||
#include "port_cube_actor.h"
|
||||
#include "port_cube_recovery.h"
|
||||
#include "../../common/cube_handshake.h"
|
||||
#include "../../common/ava2_itemshop.h"
|
||||
#include "new_mob_timer.h"
|
||||
#include "ava2_track.h"
|
||||
@@ -56,6 +59,7 @@
|
||||
|
||||
#include "DragonSoul.h"
|
||||
#include "port_switchbot.h"
|
||||
#include "port_cheque.h"
|
||||
|
||||
#ifdef __AUCTION__
|
||||
#include "auction_manager.h"
|
||||
@@ -288,6 +292,9 @@ void CInputDB::PlayerCreateSuccess(LPDESC d, const char * data)
|
||||
{ {11443, 0}, {12363, 3}, {15103, 4}, { 1053, 2}, { 2083, 1}, {16083, 7}, {17083, 8}, {13193, 9}, {14103, 10}, },
|
||||
{ {11643, 0}, {12503, 2}, {15103, 3}, { 93, 1}, {16123, 4}, {17143, 7}, {13193, 8}, {14103, 9}, { 0, 0}, },
|
||||
{ {11843, 0}, {12643, 1}, {15103, 2}, { 7083, 3}, { 5053, 4}, {16123, 6}, {17143, 7}, {13193, 8}, {14103, 9}, },
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
{ {21023, 2}, {12223, 3}, {21513, 4}, { 6023, 1}, {16143, 8}, {17103, 9}, { 0, 0}, {13193, 11}, {14103, 12}, }, // NOTE: 수인족 초기아이템.. 안쓰이는 코드니 패스
|
||||
#endif
|
||||
};
|
||||
|
||||
int job = pPacketDB->player.byJob;
|
||||
@@ -1210,6 +1217,7 @@ void CInputDB::QuestLoad(LPDESC d, const char * c_pData)
|
||||
pkPC->Build();
|
||||
ch->SetPoint(POINT_GEM, ch->GetQuestFlag("gem.points"));
|
||||
ch->PointChange(POINT_GEM, 0);
|
||||
PortChequeLoad(ch);
|
||||
|
||||
if (ch->GetDesc()->IsPhase(PHASE_GAME))
|
||||
{
|
||||
@@ -2253,6 +2261,14 @@ void CInputDB::ReloadAdmin(const char * c_pData )
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int CInputDB::Analyze(LPDESC d, BYTE bHeader, const char * c_pData)
|
||||
{
|
||||
if(bHeader==PortCube::HandshakeHeader) {
|
||||
// Process validated the complete bounded frame before this call.
|
||||
const auto* p=reinterpret_cast<const unsigned char*>(c_pData);
|
||||
const uint32_t size=uint32_t(p[0])|(uint32_t(p[1])<<8)|(uint32_t(p[2])<<16)|(uint32_t(p[3])<<24);
|
||||
PortCube::Handshake frame;
|
||||
if(PortCube::DecodeHandshake(c_pData,size,frame)&&(frame.message==PortCube::Message::RecoveryAnswer||frame.message==PortCube::Message::RecoveryImageAnswer))PortCubeRecoveryReply(m_dwHandle,c_pData,size);
|
||||
else PortCubeActorReply(m_dwHandle,c_pData,size);return 0;
|
||||
}
|
||||
switch (bHeader)
|
||||
{
|
||||
case HEADER_DG_BOOT:
|
||||
@@ -2649,6 +2665,8 @@ bool CInputDB::Process(LPDESC d, const void * orig, int bytes, int & r_iBytesPro
|
||||
m_dwHandle = *((DWORD *) (c_pData + 1)); // 4
|
||||
iSize = *((DWORD *) (c_pData + 5)); // 4
|
||||
|
||||
if(bHeader==PortCube::HandshakeHeader&&(iSize<int(PortCube::HandshakeFixed)||iSize>int(PortCube::HandshakeMaximum))){d->SetPhase(PHASE_CLOSE);return true;}
|
||||
|
||||
sys_log(1, "DBCLIENT: header %d handle %d size %d bytes %d", bHeader, m_dwHandle, iSize, bytes);
|
||||
|
||||
if (m_iBufferLeft - 9 < iSize)
|
||||
@@ -2657,6 +2675,10 @@ bool CInputDB::Process(LPDESC d, const void * orig, int bytes, int & r_iBytesPro
|
||||
const char * pRealData = (c_pData + 9);
|
||||
|
||||
if(bHeader==77 && iSize!=int(sizeof(PortEconomy::Reply))){d->SetPhase(PHASE_CLOSE);return true;}
|
||||
if(bHeader==PortCube::HandshakeHeader) {
|
||||
PortCube::Handshake frame;
|
||||
if(iSize<0||!PortCube::DecodeHandshake(pRealData,size_t(iSize),frame)||!PortCube::IsDbHandshakeReply(frame.message)){d->SetPhase(PHASE_CLOSE);return true;}
|
||||
}
|
||||
if (bHeader==76 && (iSize<int(sizeof(Ava2ShopReply))+1 || iSize>32775 || reinterpret_cast<const Ava2ShopReply*>(pRealData)->size!=iSize-sizeof(Ava2ShopReply))) { d->SetPhase(PHASE_CLOSE);return true; }
|
||||
|
||||
if (Analyze(d, bHeader, pRealData) < 0)
|
||||
@@ -2826,4 +2848,4 @@ void CInputDB::RespondChannelStatus(LPDESC desc, const char* pcData)
|
||||
BYTE bSuccess = 1;
|
||||
desc->Packet(&bSuccess, sizeof(bSuccess));
|
||||
desc->SetChannelStatusRequested(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
#include "stdafx.h"
|
||||
#include "port_material_stack_policy.h"
|
||||
#include "port_cheque.h"
|
||||
#include "constants.h"
|
||||
#include "../../common/teen_packet.h"
|
||||
#include "config.h"
|
||||
#include "utils.h"
|
||||
#include "input.h"
|
||||
#include "port_cube_recovery.h"
|
||||
#include "desc_client.h"
|
||||
#include "desc_manager.h"
|
||||
#include "char.h"
|
||||
#include "char_manager.h"
|
||||
#include "sectree_manager.h"
|
||||
#include "cmd.h"
|
||||
#include "buffer_manager.h"
|
||||
#include "protocol.h"
|
||||
@@ -94,10 +98,19 @@ static bool FN_is_battle_zone(LPCHARACTER ch)
|
||||
|
||||
void CInputLogin::Login(LPDESC d, const char * data)
|
||||
{
|
||||
const char* stackRevision = strstr(d->GetClientVersion(), "mt");
|
||||
if (!stackRevision || atoi(stackRevision + 2) < 20261030) {
|
||||
LoginFailure(d, "VERSION"); d->DelayedDisconnect(1); return;
|
||||
}
|
||||
|
||||
TPacketCGLogin * pinfo = (TPacketCGLogin *) data;
|
||||
|
||||
char login[LOGIN_MAX_LEN + 1];
|
||||
trim_and_lower(pinfo->login, login, sizeof(login));
|
||||
if (!PortMaterialStackPolicy::QAAllowed(login)) {
|
||||
LoginFailure(d, "SHUTDOWN"); d->DelayedDisconnect(1); return;
|
||||
}
|
||||
|
||||
|
||||
sys_log(0, "InputLogin::Login : %s", login);
|
||||
|
||||
@@ -146,10 +159,19 @@ void CInputLogin::Login(LPDESC d, const char * data)
|
||||
|
||||
void CInputLogin::LoginByKey(LPDESC d, const char * data)
|
||||
{
|
||||
const char* stackRevision = strstr(d->GetClientVersion(), "mt");
|
||||
if (!stackRevision || atoi(stackRevision + 2) < 20261030) {
|
||||
LoginFailure(d, "VERSION"); d->DelayedDisconnect(1); return;
|
||||
}
|
||||
|
||||
TPacketCGLogin2 * pinfo = (TPacketCGLogin2 *) data;
|
||||
|
||||
char login[LOGIN_MAX_LEN + 1];
|
||||
trim_and_lower(pinfo->login, login, sizeof(login));
|
||||
if (!PortMaterialStackPolicy::QAAllowed(login)) {
|
||||
LoginFailure(d, "SHUTDOWN"); d->DelayedDisconnect(1); return;
|
||||
}
|
||||
|
||||
|
||||
// is blocked ip?
|
||||
{
|
||||
@@ -244,6 +266,13 @@ void CInputLogin::ChangeName(LPDESC d, const char * data)
|
||||
|
||||
void CInputLogin::CharacterSelect(LPDESC d, const char * data)
|
||||
{
|
||||
const char* revision = strstr(d->GetClientVersion(), "mt");
|
||||
if (!revision || atoi(revision + 2) < 20261030) {
|
||||
LoginFailure(d, "VERSION");
|
||||
d->DelayedDisconnect(1);
|
||||
return;
|
||||
}
|
||||
|
||||
struct command_player_select * pinfo = (struct command_player_select *) data;
|
||||
const TAccountTable & c_r = d->GetAccountTable();
|
||||
|
||||
@@ -268,6 +297,7 @@ void CInputLogin::CharacterSelect(LPDESC d, const char * data)
|
||||
return;
|
||||
}
|
||||
|
||||
if(PortCubeRecoverySelect(d,c_r.players[pinfo->index].dwID,pinfo->index))return;
|
||||
TPlayerLoadPacket player_load_packet;
|
||||
|
||||
player_load_packet.account_id = c_r.id;
|
||||
@@ -380,6 +410,11 @@ bool RaceToJob(unsigned race, unsigned* ret_job)
|
||||
*ret_job = JOB_SHAMAN;
|
||||
break;
|
||||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case MAIN_RACE_WOLFMAN_M:
|
||||
*ret_job = JOB_WOLFMAN;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
@@ -562,9 +597,9 @@ typedef struct SPacketGTLogin
|
||||
|
||||
void CInputLogin::Entergame(LPDESC d, const char * data)
|
||||
{
|
||||
// PORT: wear40 moves dragon-soul/belt cells; older clients must not enter this world.
|
||||
// PORT: wear40 moves dragon-soul/belt cells; mt20261029 adds the conqueror fields and five slots; older clients must not enter this world.
|
||||
const char* revision=strstr(d->GetClientVersion(),"mt");
|
||||
if(!revision || atoi(revision+2)<20261024)
|
||||
if(!revision || atoi(revision+2)<20261030)
|
||||
{
|
||||
if(d->GetCharacter())d->GetCharacter()->ChatPacket(CHAT_TYPE_INFO,"Please update the client before entering the game.");
|
||||
d->DelayedDisconnect(1);return;
|
||||
@@ -663,6 +698,7 @@ void CInputLogin::Entergame(LPDESC d, const char * data)
|
||||
PortVipRefresh(ch, false);
|
||||
CSwitchbotManager::Instance().EnterGame(ch); // PORT: AVA2 switchbot (port_switchbot.cpp)
|
||||
Ava2ChannelList(ch); // Authoritative channel after every login/warp, including same-map transfers.
|
||||
PortChequeLoad(ch); // PORT: a Won point sent at quest load (before PHASE_GAME) never reaches the client
|
||||
|
||||
if (LC_IsEurope())
|
||||
{
|
||||
@@ -810,6 +846,19 @@ void CInputLogin::Entergame(LPDESC d, const char * data)
|
||||
sys_log(0, "TEEN_SEND: (%u, %s)", d->GetAccountTable().id, ch->GetName());
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
if (ch->IsPC() && ch->IsConquerorMap(ch->GetMapIndex()))
|
||||
{
|
||||
TPacketGCSungmaAttrUpdate p;
|
||||
p.bHeader = HEADER_GC_SUNGMA_ATTR_UPDATE;
|
||||
p.bSTR = SECTREE_MANAGER::instance().GetSungmaValueAffectByRegion(ch->GetMapIndex(), AFFECT_SUNGMA_STR);
|
||||
p.bHP = SECTREE_MANAGER::instance().GetSungmaValueAffectByRegion(ch->GetMapIndex(), AFFECT_SUNGMA_HP);
|
||||
p.bMOVE = SECTREE_MANAGER::instance().GetSungmaValueAffectByRegion(ch->GetMapIndex(), AFFECT_SUNGMA_MOVE);
|
||||
p.bINMUNE = SECTREE_MANAGER::instance().GetSungmaValueAffectByRegion(ch->GetMapIndex(), AFFECT_SUNGMA_INMUNE);
|
||||
ch->GetDesc()->Packet(&p, sizeof(p));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ch->GetHorseLevel() > 0)
|
||||
{
|
||||
DWORD pid = ch->GetPlayerID();
|
||||
@@ -1125,11 +1174,23 @@ int CInputLogin::Analyze(LPDESC d, BYTE bHeader, const char * c_pData)
|
||||
break;
|
||||
|
||||
case HEADER_CG_CLIENT_VERSION:
|
||||
Version(d->GetCharacter(), c_pData);
|
||||
{
|
||||
// Version is now sent before character selection; no actor exists yet.
|
||||
const auto* packet = reinterpret_cast<const TPacketCGClientVersion*>(c_pData);
|
||||
char timestamp[sizeof(packet->timestamp) + 1] = {};
|
||||
memcpy(timestamp, packet->timestamp, sizeof(packet->timestamp));
|
||||
d->SetClientVersion(timestamp);
|
||||
}
|
||||
break;
|
||||
|
||||
case HEADER_CG_CLIENT_VERSION2:
|
||||
Version(d->GetCharacter(), c_pData);
|
||||
{
|
||||
// Version is now sent before character selection; no actor exists yet.
|
||||
const auto* packet = reinterpret_cast<const TPacketCGClientVersion*>(c_pData);
|
||||
char timestamp[sizeof(packet->timestamp) + 1] = {};
|
||||
memcpy(timestamp, packet->timestamp, sizeof(packet->timestamp));
|
||||
d->SetClientVersion(timestamp);
|
||||
}
|
||||
break;
|
||||
|
||||
// case HEADER_CG_HS_ACK:
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
#include "DragonSoul.h"
|
||||
#include "port_switchbot.h"
|
||||
#include "ava2_native_packets.h"
|
||||
#include "cube.h"
|
||||
#include "port_cheque.h"
|
||||
|
||||
extern void SendShout(const char * szText, BYTE bEmpire);
|
||||
extern int g_nPortalLimitTime;
|
||||
@@ -1074,15 +1076,16 @@ int CInputMain::Shop(LPCHARACTER ch, const char * data, size_t uiBytes)
|
||||
|
||||
case SHOP_SUBHEADER_CG_SELL2:
|
||||
{
|
||||
if (uiBytes < sizeof(BYTE) + sizeof(BYTE))
|
||||
if (uiBytes < sizeof(BYTE) + sizeof(WORD))
|
||||
return -1;
|
||||
|
||||
BYTE pos = *(c_pData++);
|
||||
BYTE count = *(c_pData);
|
||||
WORD count = 0;
|
||||
memcpy(&count, c_pData, sizeof(count));
|
||||
|
||||
sys_log(0, "INPUT: %s SHOP: SELL2", ch->GetName());
|
||||
CShopManager::instance().Sell(ch, pos, count);
|
||||
return sizeof(BYTE) + sizeof(BYTE);
|
||||
return sizeof(BYTE) + sizeof(WORD);
|
||||
}
|
||||
|
||||
default:
|
||||
@@ -1243,6 +1246,11 @@ void CInputMain::Exchange(LPCHARACTER ch, const char * data)
|
||||
}
|
||||
break;
|
||||
|
||||
case EXCHANGE_SUBHEADER_CG_CHEQUE_ADD: // arg1 == amount of won (PORT)
|
||||
if (ch->GetExchange() && ch->GetExchange()->GetCompany()->GetAcceptStatus() != true)
|
||||
ch->GetExchange()->AddCheque(pinfo->arg1);
|
||||
break;
|
||||
|
||||
case EXCHANGE_SUBHEADER_CG_ACCEPT: // arg1 == not used
|
||||
if (ch->GetExchange())
|
||||
{
|
||||
@@ -1396,6 +1404,10 @@ bool CheckComboHack(LPCHARACTER ch, BYTE bArg, DWORD dwTime, bool CheckSpeedHack
|
||||
ch->GetWear(WEAR_WEAPON) &&
|
||||
ch->GetWear(WEAR_WEAPON)->GetSubType() == WEAPON_DAGGER)
|
||||
ch->SetValidComboInterval(300);
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
else if (bArg == 21 && idx == 2 && ch->GetComboSequence() == 5 && ch->GetJob() == JOB_WOLFMAN && ch->GetWear(WEAR_WEAPON) && ch->GetWear(WEAR_WEAPON)->GetSubType() == WEAPON_CLAW)
|
||||
ch->SetValidComboInterval(300);
|
||||
#endif
|
||||
else if (ComboSequenceBySkillLevel[idx][ch->GetComboSequence()] != bArg)
|
||||
{
|
||||
HackScalar = 1;
|
||||
@@ -1743,6 +1755,11 @@ void CInputMain::Attack(LPCHARACTER ch, const BYTE header, const char* data)
|
||||
case SKILL_NOEJEON:
|
||||
case SKILL_CHAIN:
|
||||
case SKILL_HORSE_WILDATTACK_RANGE:
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
case SKILL_ILGWANGPYO:
|
||||
case SKILL_MABEOBAGGWI:
|
||||
case SKILL_METEO:
|
||||
#endif
|
||||
if (HEADER_CG_SHOOT != type->header)
|
||||
{
|
||||
if (test_server)
|
||||
@@ -2955,7 +2972,9 @@ void CInputMain::Hack(LPCHARACTER ch, const char * c_pData)
|
||||
int CInputMain::MyShop(LPCHARACTER ch, const char * c_pData, size_t uiBytes)
|
||||
{
|
||||
TPacketCGMyShop * p = (TPacketCGMyShop *) c_pData;
|
||||
int iExtraLen = p->bCount * sizeof(TShopItemTable);
|
||||
// PORT: Won-aware clients append int32 cheque[bCount] after the items.
|
||||
const bool withCheque = PortChequeClientSupported(ch);
|
||||
int iExtraLen = p->bCount * (sizeof(TShopItemTable) + (withCheque ? sizeof(int32_t) : 0));
|
||||
|
||||
if (uiBytes < sizeof(TPacketCGMyShop) + iExtraLen)
|
||||
return -1;
|
||||
@@ -2977,7 +2996,8 @@ int CInputMain::MyShop(LPCHARACTER ch, const char * c_pData, size_t uiBytes)
|
||||
}
|
||||
|
||||
sys_log(0, "MyShop count %d", p->bCount);
|
||||
ch->OpenMyShop(p->szSign, (TShopItemTable *) (c_pData + sizeof(TPacketCGMyShop)), p->bCount);
|
||||
const int32_t * pCheque = withCheque ? (const int32_t *) (c_pData + sizeof(TPacketCGMyShop) + p->bCount * sizeof(TShopItemTable)) : NULL;
|
||||
ch->OpenMyShop(p->szSign, (TShopItemTable *) (c_pData + sizeof(TPacketCGMyShop)), p->bCount, pCheque);
|
||||
return (iExtraLen);
|
||||
}
|
||||
|
||||
@@ -3678,6 +3698,15 @@ int CInputMain::Analyze(LPDESC d, BYTE bHeader, const char * c_pData)
|
||||
|
||||
case HEADER_CG_AVA2_DROP:
|
||||
PortNativeDrop(ch,*reinterpret_cast<const TPacketCGAva2Drop*>(c_pData));break;
|
||||
case HEADER_CG_CUBE_RENEWAL:
|
||||
{
|
||||
const TPacketCGCubeRenewalSend* p = reinterpret_cast<const TPacketCGCubeRenewalSend*>(c_pData);
|
||||
if (p->subheader == CUBE_RENEWAL_SUB_HEADER_MAKE_ITEM)
|
||||
CubeRenewal_Make(ch, p->index_item, p->count_item);
|
||||
else if (p->subheader == CUBE_RENEWAL_SUB_HEADER_CLOSE)
|
||||
CubeRenewal_Close(ch);
|
||||
break;
|
||||
}
|
||||
#ifdef ENABLE_SHOP_SEARCH_SYSTEM
|
||||
case HEADER_CG_SHOP_SEARCH:
|
||||
ShopSearch(ch, c_pData);
|
||||
|
||||
+127
-15
@@ -1,4 +1,10 @@
|
||||
#include "stdafx.h"
|
||||
#include "port_material_stack_policy.h"
|
||||
#include "questmanager.h"
|
||||
#include "port_cube_actor.h"
|
||||
#include "../../common/cube_mutation.h"
|
||||
#include "../../common/economy.h"
|
||||
#include "../../common/cube_presentation.h"
|
||||
#include "port_attr_lock.h"
|
||||
#include "utils.h"
|
||||
#include "config.h"
|
||||
@@ -24,6 +30,8 @@
|
||||
#include "../../common/VnumHelper.h"
|
||||
#include "PetSystem.h"
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
#include "event_queue.h"
|
||||
|
||||
CItem::CItem(DWORD dwVnum)
|
||||
: m_dwVnum(dwVnum), m_bWindow(0), m_dwID(0), m_bEquipped(false), m_dwVID(0), m_wCell(0), m_dwCount(0), m_lFlag(0), m_dwLastOwnerPID(0),
|
||||
@@ -69,6 +77,7 @@ void CItem::Initialize()
|
||||
|
||||
m_bSkipSave = false;
|
||||
m_deferChestUpdate = false;
|
||||
m_portCubeTemplate = false;
|
||||
m_dwLastOwnerPID = 0;
|
||||
}
|
||||
|
||||
@@ -211,6 +220,7 @@ void CItem::AddFlag(long bit)
|
||||
|
||||
void CItem::UpdatePacket()
|
||||
{
|
||||
if(m_portCubeTemplate)return;
|
||||
if(m_deferChestUpdate) return;
|
||||
if (!m_pOwner || !m_pOwner->GetDesc())
|
||||
return;
|
||||
@@ -219,6 +229,19 @@ void CItem::UpdatePacket()
|
||||
if (m_bWindow == SWITCHBOT)
|
||||
return;
|
||||
|
||||
if (m_bWindow == SAFEBOX || m_bWindow == MALL)
|
||||
{
|
||||
TPacketGCItemSet packet = {};
|
||||
packet.header = m_bWindow == SAFEBOX ? HEADER_GC_SAFEBOX_SET : HEADER_GC_MALL_SET;
|
||||
packet.Cell = TItemPos(m_bWindow, m_wCell);
|
||||
packet.vnum = GetVnum(); packet.count = GetCount();
|
||||
packet.flags = GetFlag(); packet.anti_flags = GetAntiFlag();
|
||||
memcpy(packet.alSockets, m_alSockets, sizeof(packet.alSockets));
|
||||
memcpy(packet.aAttr, m_aAttr, sizeof(packet.aAttr));
|
||||
m_pOwner->GetDesc()->Packet(&packet, sizeof(packet));
|
||||
SendPortExtra();
|
||||
return;
|
||||
}
|
||||
TPacketGCItemUpdate pack;
|
||||
|
||||
pack.header = HEADER_GC_ITEM_UPDATE;
|
||||
@@ -236,13 +259,62 @@ void CItem::UpdatePacket()
|
||||
SendPortExtra();
|
||||
}
|
||||
|
||||
unsigned CItem::GetStackLimit() const
|
||||
{
|
||||
return m_pProto ? PortMaterialStackPolicy::Limit(m_pProto->bType,
|
||||
(m_lFlag & ITEM_FLAG_STACKABLE) != 0,
|
||||
(m_pProto->dwAntiFlags & ITEM_ANTIFLAG_STACK) != 0, m_pProto->dwVnum) : 1;
|
||||
}
|
||||
|
||||
unsigned CItem::GetStackRoom()
|
||||
{
|
||||
// Rollback disables growth while retaining wide-count reads and deductions.
|
||||
unsigned limit = GetStackLimit();
|
||||
if ((PortMaterialStackPolicy::LegacyGrowthMode() || quest::CQuestManager::instance().GetEventFlag("material_stack_legacy_mode")))
|
||||
limit = std::min(limit, 200u);
|
||||
return GetCount() < limit ? limit - GetCount() : 0;
|
||||
}
|
||||
|
||||
bool CItem::CanStackWith(const CItem* other) const
|
||||
{
|
||||
if (!other || !m_pProto || !other->m_pProto ||
|
||||
m_dwVnum != other->m_dwVnum || m_dwMaskVnum != other->m_dwMaskVnum ||
|
||||
m_dwSIGVnum != other->m_dwSIGVnum || m_lFlag != other->m_lFlag ||
|
||||
!(m_lFlag & ITEM_FLAG_STACKABLE) || !(other->m_lFlag & ITEM_FLAG_STACKABLE) ||
|
||||
((m_pProto->dwAntiFlags | other->m_pProto->dwAntiFlags) & ITEM_ANTIFLAG_STACK) ||
|
||||
m_bExchanging || other->m_bExchanging || m_isLocked || other->m_isLocked)
|
||||
return false;
|
||||
CItem* self = const_cast<CItem*>(this);
|
||||
CItem* source = const_cast<CItem*>(other);
|
||||
const unsigned mask = PortAttrLockGet(self);
|
||||
const unsigned otherMask = PortAttrLockGet(source);
|
||||
if (!self->m_portAttrLockLoaded || !source->m_portAttrLockLoaded) return false;
|
||||
return !memcmp(m_alSockets, other->m_alSockets, sizeof(m_alSockets)) &&
|
||||
!memcmp(m_aAttr, other->m_aAttr, sizeof(m_aAttr)) &&
|
||||
!memcmp(&m_portExtra, &other->m_portExtra, sizeof(m_portExtra)) &&
|
||||
mask == otherMask;
|
||||
}
|
||||
|
||||
bool CItem::CopyStackStateTo(CItem* target)
|
||||
{
|
||||
if (!target || target->GetOriginalVnum() != GetOriginalVnum()) return false;
|
||||
const unsigned mask = PortAttrLockGet(this);
|
||||
if (!m_portAttrLockLoaded) return false;
|
||||
target->SetSockets(GetSockets());
|
||||
CopyAttributeTo(target);
|
||||
target->SetPortExtra(GetPortExtra());
|
||||
target->m_lFlag = m_lFlag;
|
||||
target->m_dwMaskVnum = m_dwMaskVnum;
|
||||
target->m_dwSIGVnum = m_dwSIGVnum;
|
||||
if (mask && !PortAttrLockSet(NULL, target, mask)) return false;
|
||||
target->m_portAttrLockLoaded = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
DWORD CItem::GetCount()
|
||||
{
|
||||
if (GetType() == ITEM_ELK) return MIN(m_dwCount, INT_MAX);
|
||||
else
|
||||
{
|
||||
return MIN(m_dwCount, 200);
|
||||
}
|
||||
// Never truncate saved counts while loading, transferring, or rolling back.
|
||||
return m_dwCount;
|
||||
}
|
||||
|
||||
bool CItem::SetCount(DWORD count)
|
||||
@@ -253,7 +325,8 @@ bool CItem::SetCount(DWORD count)
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dwCount = MIN(count, ITEM_MAX_COUNT);
|
||||
if (count > GetStackLimit()) return false;
|
||||
m_dwCount = count;
|
||||
}
|
||||
|
||||
if (count == 0 && m_pOwner)
|
||||
@@ -412,7 +485,17 @@ bool CItem::AddToCharacter(LPCHARACTER ch, TItemPos Cell)
|
||||
if (ch->GetDesc())
|
||||
m_dwLastOwnerPID = ch->GetPlayerID();
|
||||
|
||||
// AVA2 sash: a fresh sash gets the starting absorption of its grade
|
||||
PortCubeInitNewAttach();
|
||||
event_cancel(&m_pkDestroyEvent);
|
||||
ch->SetItem(TItemPos(window_type, pos), this);
|
||||
m_pOwner = ch;
|
||||
Save();
|
||||
return true;
|
||||
}
|
||||
|
||||
void CItem::PortCubeInitNewAttach()
|
||||
{
|
||||
// Shared with the new Cube template factory; persisted restore skips this.
|
||||
if (GetType() == ITEM_COSTUME && GetSubType() == COSTUME_SASH && GetSocket(SASH_ABSORPTION_SOCKET) == 0)
|
||||
{
|
||||
long lVal;
|
||||
@@ -426,13 +509,22 @@ bool CItem::AddToCharacter(LPCHARACTER ch, TItemPos Cell)
|
||||
SetSocket(SASH_ABSORPTION_SOCKET, lVal);
|
||||
}
|
||||
|
||||
event_cancel(&m_pkDestroyEvent);
|
||||
}
|
||||
|
||||
ch->SetItem(TItemPos(window_type, pos), this);
|
||||
m_pOwner = ch;
|
||||
|
||||
Save();
|
||||
return true;
|
||||
bool CItem::PortCubeRestoreMetadata(const PortEconomy::Reward& r)
|
||||
{
|
||||
if(!m_portCubeTemplate||m_pOwner||GetSectree()||r.id!=GetID()||r.vnum!=GetOriginalVnum()||
|
||||
!r.count||r.count>GetStackLimit()||(!IsStackable()&&r.count!=1))return false;
|
||||
m_dwCount=r.count;
|
||||
for(unsigned i=0;i<3;++i)m_alSockets[i]=r.sockets[i];
|
||||
for(unsigned i=0;i<7;++i){m_aAttr[i].bType=r.types[i];m_aAttr[i].sValue=r.values[i];}
|
||||
static_assert(sizeof(m_portExtra)==sizeof(r.extra),"exact restored extra metadata");
|
||||
std::memcpy(&m_portExtra,r.extra,sizeof(r.extra));return true;
|
||||
}
|
||||
void CItem::PortCubeAttachRestored(LPCHARACTER owner,WORD cell)
|
||||
{
|
||||
m_pOwner=owner;m_dwLastOwnerPID=owner->GetPlayerID();m_wCell=cell;
|
||||
m_bWindow=INVENTORY;m_portCubeTemplate=false;m_bSkipSave=true;
|
||||
}
|
||||
|
||||
LPITEM CItem::RemoveFromGround()
|
||||
@@ -526,6 +618,12 @@ bool CItem::CanUsedBy(LPCHARACTER ch)
|
||||
if (GetAntiFlag() & ITEM_ANTIFLAG_SURA)
|
||||
return false;
|
||||
break;
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
case JOB_WOLFMAN:
|
||||
if (GetAntiFlag() & ITEM_ANTIFLAG_WOLFMAN)
|
||||
return false;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -1254,12 +1352,19 @@ void CItem::SetExchanging(bool bOn)
|
||||
|
||||
void CItem::Save()
|
||||
{
|
||||
// Unowned factory metadata is not an actor mutation or a delayed save.
|
||||
if(m_portCubeTemplate)return;
|
||||
// Mutation notification is not a veto: preserve the original save/expiry.
|
||||
if(GetOwner())PortCubeAssetMutation(GetOwner(),PortCube::ItemWrite);
|
||||
else PortCubeAssetMutationByPID(GetLastOwnerPID(),PortCube::ItemWrite);
|
||||
if (m_bSkipSave)
|
||||
return;
|
||||
|
||||
ITEM_MANAGER::instance().DelayedSave(this);
|
||||
}
|
||||
|
||||
#include "port_cube_item.inc"
|
||||
|
||||
bool CItem::CreateSocket(BYTE bSlot, BYTE bGold)
|
||||
{
|
||||
assert(bSlot < ITEM_SOCKET_MAX_NUM);
|
||||
@@ -1294,7 +1399,7 @@ void CItem::SetSocket(int i, long v, bool bLog)
|
||||
m_alSockets[i] = v;
|
||||
UpdatePacket();
|
||||
Save();
|
||||
if (bLog)
|
||||
if (bLog && !m_portCubeTemplate)
|
||||
LogManager::instance().ItemLog(i, v, 0, GetID(), "SET_SOCKET", "", "", GetOriginalVnum());
|
||||
}
|
||||
|
||||
@@ -1645,7 +1750,7 @@ void CItem::SetTimerBasedOnWearExpireEvent(LPEVENT pkEvent)
|
||||
|
||||
EVENTFUNC(real_time_expire_event)
|
||||
{
|
||||
const item_vid_event_info* info = reinterpret_cast<const item_vid_event_info*>(event->info);
|
||||
const item_vid_event_info* info = dynamic_cast<const item_vid_event_info*>(event->info); // PORT: prepared clock info is a checked subtype.
|
||||
|
||||
if (NULL == info)
|
||||
return 0;
|
||||
@@ -2262,6 +2367,8 @@ int CItem::GetLevelLimit()
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include "port_cube_lifecycle.inc"
|
||||
|
||||
bool CItem::OnAfterCreatedItem()
|
||||
{
|
||||
// 아이템을 한 번이라도 사용했다면, 그 이후엔 사용 중이지 않아도 시간이 차감되는 방식
|
||||
@@ -2394,6 +2501,11 @@ void PortItemExtraSend(CHARACTER* owner,CItem* item,BYTE window,WORD cell)
|
||||
if(!owner || !item || !owner->GetDesc())return;
|
||||
const char* version=strstr(owner->GetDesc()->GetClientVersion(),"mt");
|
||||
if(!version || atoi(version+2)<20261022)return;
|
||||
if(atoi(version+2)>=20261025) {
|
||||
PortCubeView::Writer w;w.n(93,1);w.n(88,4);w.n(12,1);w.n(window,1);w.n(cell,2);w.n(item->GetVnum(),4);w.n(item->GetID(),4);w.n(item->GetCount(),2);
|
||||
static_assert(sizeof(item->GetPortExtra())==69,"full count companion extra");w.bytes.append(reinterpret_cast<const char*>(&item->GetPortExtra()),69);
|
||||
owner->GetDesc()->Packet(w.bytes.data(),w.bytes.size());return;
|
||||
}
|
||||
#pragma pack(push,1)
|
||||
struct Packet { uint8_t header;uint32_t size;uint8_t op,window;uint16_t cell;uint32_t vnum,id;PortItemExtra extra; };
|
||||
#pragma pack(pop)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define __INC_METIN_II_GAME_ITEM_H__
|
||||
|
||||
#include "entity.h"
|
||||
namespace PortEconomy {struct Reward;}
|
||||
|
||||
class CItem : public CEntity
|
||||
{
|
||||
@@ -22,6 +23,11 @@ class CItem : public CEntity
|
||||
|
||||
long FindApplyValue(BYTE bApplyType);
|
||||
|
||||
unsigned GetStackLimit() const;
|
||||
unsigned GetStackRoom();
|
||||
bool CanStackWith(const CItem* other) const;
|
||||
bool CopyStackStateTo(CItem* target);
|
||||
|
||||
bool IsStackable() { return (GetFlag() & ITEM_FLAG_STACKABLE)?true:false; }
|
||||
|
||||
void Initialize();
|
||||
@@ -150,6 +156,17 @@ class CItem : public CEntity
|
||||
|
||||
void SetSkipSave(bool b) { m_bSkipSave = b; }
|
||||
bool GetSkipSave() { return m_bSkipSave; }
|
||||
bool PortCubeIsTemplate() const { return m_portCubeTemplate; }
|
||||
void PortCubeMarkTemplate() { m_portCubeTemplate=true; m_bSkipSave=true; }
|
||||
void PortCubeInitNewAttach();
|
||||
bool PortCubeRestoreMetadata(const PortEconomy::Reward&);
|
||||
void PortCubeAttachRestored(LPCHARACTER,WORD);
|
||||
bool PortCubeHasPendingMutation() const;
|
||||
unsigned PortCubeRestoreEventMask();
|
||||
bool PortCubeRestoreEligible(bool savingEnabled=false);
|
||||
bool PortCubeRestoreEventsReady(bool savingEnabled=false);
|
||||
bool PortCubePrepareRestoreEvents();
|
||||
void PortCubeCancelRestoreEvents();
|
||||
|
||||
bool IsOwnership(LPCHARACTER ch);
|
||||
void SetOwnership(LPCHARACTER ch, int iSec = 10);
|
||||
@@ -327,6 +344,7 @@ class CItem : public CEntity
|
||||
|
||||
bool m_bSkipSave;
|
||||
bool m_deferChestUpdate = false;
|
||||
bool m_portCubeTemplate = false;
|
||||
|
||||
bool m_isLocked;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ int CItem::GetAttributeSetIndex()
|
||||
{
|
||||
if (GetType() == ITEM_WEAPON)
|
||||
{
|
||||
if (GetSubType() == WEAPON_ARROW)
|
||||
if (GetSubType() == WEAPON_ARROW || GetSubType() == WEAPON_QUIVER)
|
||||
return -1;
|
||||
|
||||
return ATTRIBUTE_SET_WEAPON;
|
||||
@@ -332,7 +332,7 @@ void CItem::SetAttribute(int i, BYTE bType, short sValue)
|
||||
UpdatePacket();
|
||||
Save();
|
||||
|
||||
if (bType)
|
||||
if (bType && !PortCubeIsTemplate())
|
||||
{
|
||||
const char * pszIP = NULL;
|
||||
|
||||
@@ -361,7 +361,7 @@ void CItem::SetForceAttribute(int i, BYTE bType, short sValue)
|
||||
UpdatePacket();
|
||||
Save();
|
||||
|
||||
if (bType)
|
||||
if (bType && !PortCubeIsTemplate())
|
||||
{
|
||||
const char * pszIP = NULL;
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#include "locale_service.h"
|
||||
#include "item.h"
|
||||
#include "item_manager.h"
|
||||
#include "port_cube_factory.h"
|
||||
#include "port_material_stack_policy.h"
|
||||
#include "mob_manager.h"
|
||||
#include "port_calendar_runtime.h"
|
||||
|
||||
@@ -148,6 +150,11 @@ bool ITEM_MANAGER::Initialize(TItemTable * table, int size)
|
||||
|
||||
LPITEM ITEM_MANAGER::CreateItem(DWORD vnum, DWORD count, DWORD id, bool bTryMagic, int iRarePct, bool bSkipSave)
|
||||
{
|
||||
PortCubeFactorySlot* cubeSlot=PortCubeCurrentFactorySlot();
|
||||
if(cubeSlot) {
|
||||
if(cubeSlot->entered||!cubeSlot->id||cubeSlot->vnum!=vnum||id!=(cubeSlot->restoring?cubeSlot->id:0)||count!=cubeSlot->count||bTryMagic||!bSkipSave)return NULL;
|
||||
cubeSlot->entered=true;
|
||||
}
|
||||
if (0 == vnum)
|
||||
return NULL;
|
||||
|
||||
@@ -184,13 +191,21 @@ LPITEM ITEM_MANAGER::CreateItem(DWORD vnum, DWORD count, DWORD id, bool bTryMagi
|
||||
|
||||
if (NULL == table)
|
||||
return NULL;
|
||||
const unsigned stackLimit = PortMaterialStackPolicy::Limit(table->bType,
|
||||
(table->dwFlags & ITEM_FLAG_STACKABLE) != 0,
|
||||
(table->dwAntiFlags & ITEM_ANTIFLAG_STACK) != 0, table->dwVnum);
|
||||
if (table->bType != ITEM_ELK && (table->dwFlags & ITEM_FLAG_STACKABLE) && (!count || count > stackLimit)) return NULL;
|
||||
if (!id && table->bType != ITEM_ELK && count > 200 &&
|
||||
(PortMaterialStackPolicy::LegacyGrowthMode() || quest::CQuestManager::instance().GetEventFlag("material_stack_legacy_mode"))) return NULL;
|
||||
|
||||
LPITEM item = NULL;
|
||||
|
||||
//id로 검사해서 존재한다면 -- 리턴!
|
||||
if (m_map_pkItemByID.find(id) != m_map_pkItemByID.end())
|
||||
const DWORD lookupID=cubeSlot?cubeSlot->id:id;
|
||||
if (m_map_pkItemByID.find(lookupID) != m_map_pkItemByID.end() &&
|
||||
!(cubeSlot&&cubeSlot->restoring&&cubeSlot->replacement==m_map_pkItemByID.find(lookupID)->second))
|
||||
{
|
||||
item = m_map_pkItemByID[id];
|
||||
item = m_map_pkItemByID[lookupID];
|
||||
LPCHARACTER owner = item->GetOwner();
|
||||
sys_err("ITEM_ID_DUP: %u %s owner %p", id, item->GetName(), get_pointer(owner));
|
||||
return NULL;
|
||||
@@ -207,6 +222,7 @@ LPITEM ITEM_MANAGER::CreateItem(DWORD vnum, DWORD count, DWORD id, bool bTryMagi
|
||||
|
||||
//초기화 하고. 테이블 셋하고
|
||||
item->Initialize();
|
||||
if(cubeSlot){cubeSlot->item=item;item->PortCubeMarkTemplate();}
|
||||
item->SetProto(table);
|
||||
item->SetMaskVnum(dwMaskVnum);
|
||||
|
||||
@@ -221,7 +237,7 @@ LPITEM ITEM_MANAGER::CreateItem(DWORD vnum, DWORD count, DWORD id, bool bTryMagi
|
||||
}
|
||||
else
|
||||
{
|
||||
item->SetID(GetNewID());
|
||||
item->SetID(cubeSlot?cubeSlot->id:GetNewID());
|
||||
|
||||
if (item->GetType() == ITEM_UNIQUE) // 유니크 아이템은 생성시에 소켓에 남은시간을 기록한다.
|
||||
{
|
||||
@@ -265,7 +281,7 @@ LPITEM ITEM_MANAGER::CreateItem(DWORD vnum, DWORD count, DWORD id, bool bTryMagi
|
||||
;
|
||||
else if (item->IsStackable()) // 합칠 수 있는 아이템의 경우
|
||||
{
|
||||
count = MINMAX(1, count, ITEM_MAX_COUNT);
|
||||
|
||||
|
||||
if (bTryMagic && count <= 1 && IS_SET(item->GetFlag(), ITEM_FLAG_MAKECOUNT))
|
||||
count = item->GetValue(1);
|
||||
@@ -273,7 +289,10 @@ LPITEM ITEM_MANAGER::CreateItem(DWORD vnum, DWORD count, DWORD id, bool bTryMagi
|
||||
else
|
||||
count = 1;
|
||||
|
||||
item->SetVID(++m_dwVIDCount);
|
||||
if (table->bType != ITEM_ELK && (!count || count > stackLimit)) {
|
||||
M2_DESTROY_ITEM(item); return NULL;
|
||||
}
|
||||
if(!cubeSlot)item->SetVID(++m_dwVIDCount);
|
||||
|
||||
if (bSkipSave == false)
|
||||
m_VIDMap.insert(ITEM_VID_MAP::value_type(item->GetVID(), item));
|
||||
@@ -284,9 +303,9 @@ LPITEM ITEM_MANAGER::CreateItem(DWORD vnum, DWORD count, DWORD id, bool bTryMagi
|
||||
if (!item->SetCount(count))
|
||||
return NULL;
|
||||
|
||||
item->SetSkipSave(false);
|
||||
if(!cubeSlot)item->SetSkipSave(false);
|
||||
|
||||
if (item->GetType() == ITEM_UNIQUE && item->GetValue(2) != 0)
|
||||
if (!cubeSlot && item->GetType() == ITEM_UNIQUE && item->GetValue(2) != 0)
|
||||
item->StartUniqueExpireEvent();
|
||||
|
||||
for (int i=0 ; i < ITEM_LIMIT_MAX_NUM ; i++)
|
||||
@@ -303,7 +322,7 @@ LPITEM ITEM_MANAGER::CreateItem(DWORD vnum, DWORD count, DWORD id, bool bTryMagi
|
||||
item->SetSocket(0, time(0) + 60*60*24*7);
|
||||
}
|
||||
|
||||
item->StartRealTimeExpireEvent();
|
||||
if(!cubeSlot)item->StartRealTimeExpireEvent();
|
||||
}
|
||||
|
||||
// 기존 유니크 아이템처럼 착용시에만 사용가능 시간이 차감되는 방식
|
||||
@@ -313,7 +332,7 @@ LPITEM ITEM_MANAGER::CreateItem(DWORD vnum, DWORD count, DWORD id, bool bTryMagi
|
||||
// 아이템몰로 지급하는 경우에는 이 로직에 들어오기 전에 Socket0 값이 세팅이 되어 있어야 한다.
|
||||
if (true == item->IsEquipped())
|
||||
{
|
||||
item->StartTimerBasedOnWearExpireEvent();
|
||||
if(!cubeSlot)item->StartTimerBasedOnWearExpireEvent();
|
||||
}
|
||||
else if(0 == id)
|
||||
{
|
||||
@@ -439,6 +458,7 @@ void ITEM_MANAGER::FlushDelayedSave(LPITEM item)
|
||||
|
||||
void ITEM_MANAGER::SaveSingleItem(LPITEM item)
|
||||
{
|
||||
if(!item||item->PortCubeIsTemplate())return;
|
||||
if (!item->GetOwner())
|
||||
{
|
||||
DWORD dwID = item->GetID();
|
||||
@@ -551,7 +571,7 @@ void ITEM_MANAGER::DestroyItem(LPITEM item, const char* file, size_t line)
|
||||
DWORD dwID = item->GetID();
|
||||
sys_log(2, "ITEM_DESTROY %s:%u", item->GetName(), dwID);
|
||||
|
||||
if (!item->GetSkipSave() && dwID)
|
||||
if (!item->PortCubeIsTemplate() && !item->GetSkipSave() && dwID)
|
||||
{
|
||||
DWORD dwOwnerID = item->GetLastOwnerPID();
|
||||
|
||||
@@ -564,10 +584,10 @@ void ITEM_MANAGER::DestroyItem(LPITEM item, const char* file, size_t line)
|
||||
sys_log(2, "ITEM_DESTROY_SKIP %s:%u (skip=%d)", item->GetName(), dwID, item->GetSkipSave());
|
||||
}
|
||||
|
||||
if (dwID)
|
||||
if (dwID && !item->PortCubeIsTemplate())
|
||||
m_map_pkItemByID.erase(dwID);
|
||||
|
||||
m_VIDMap.erase(item->GetVID());
|
||||
if(!item->PortCubeIsTemplate())m_VIDMap.erase(item->GetVID());
|
||||
|
||||
#ifdef M2_USE_POOL
|
||||
pool_.Destroy(item);
|
||||
@@ -613,7 +633,7 @@ TItemTable * ITEM_MANAGER::GetTable(DWORD vnum)
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -997,7 +1017,7 @@ bool ITEM_MANAGER::CreateDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller, std::
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// BuyerTheitGloves Item Group
|
||||
{
|
||||
if (pkKiller->GetPremiumRemainSeconds(PREMIUM_ITEM) > 0 ||
|
||||
@@ -1024,7 +1044,7 @@ bool ITEM_MANAGER::CreateDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller, std::
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 잡템
|
||||
if (pkChr->GetMobDropItemVnum())
|
||||
{
|
||||
@@ -1605,7 +1625,7 @@ void ITEM_MANAGER::CreateQuestDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller,
|
||||
if ( (item=CreateItem(halloween_item, 1, 0, true)) )
|
||||
vec_item.push_back(item);
|
||||
}
|
||||
|
||||
|
||||
if ( GetDropPerKillPct(100, g_iUseLocale ? 2000 : 800, iDeltaPercent, "ramadan_drop") >= number(1, iRandRange) )
|
||||
{
|
||||
const static DWORD ramadan_item = 30315;
|
||||
@@ -1801,3 +1821,6 @@ void ITEM_MANAGER::CopyAllAttrTo(LPITEM pkOldItem, LPITEM pkNewItem)
|
||||
}
|
||||
|
||||
#include "port_wiki_queries.inc"
|
||||
|
||||
#include "port_cube_flush.inc"
|
||||
#include "port_cube_registry.inc"
|
||||
|
||||
@@ -43,6 +43,9 @@ class CSpecialItemGroup
|
||||
DRAIN_HP,
|
||||
POISON,
|
||||
MOB_GROUP,
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
BLEEDING,
|
||||
#endif
|
||||
};
|
||||
|
||||
// QUEST 타입은 퀘스트 스크립트에서 vnum.sig_use를 사용할 수 있는 그룹이다.
|
||||
@@ -390,6 +393,7 @@ class ITEM_MANAGER : public singleton<ITEM_MANAGER>
|
||||
void GracefulShutdown();
|
||||
|
||||
DWORD GetNewID();
|
||||
bool PortCubeSwapRegistry(const std::vector<LPITEM>& before,const std::vector<LPITEM>& after);
|
||||
bool SetMaxItemID(TItemIDRangeTable range); // 최대 고유 아이디를 지정
|
||||
bool SetMaxSpareItemID(TItemIDRangeTable range);
|
||||
|
||||
@@ -399,6 +403,7 @@ class ITEM_MANAGER : public singleton<ITEM_MANAGER>
|
||||
void DelayedSave(LPITEM item);
|
||||
void FlushDelayedSave(LPITEM item); // Delayed 리스트에 있다면 지우고 저장한다. 끊김 처리시 사용 됨.
|
||||
void SaveSingleItem(LPITEM item);
|
||||
void FlushDelayedSaveForPlayer(DWORD pid);
|
||||
|
||||
LPITEM CreateItem(DWORD vnum, DWORD count = 1, DWORD dwID = 0, bool bTryMagic = false, int iRarePct = -1, bool bSkipSave = false);
|
||||
#ifndef DEBUG_ALLOC
|
||||
|
||||
@@ -2,6 +2,32 @@
|
||||
#include "stdafx.h"
|
||||
#include "desc_client.h"
|
||||
#include "item_manager.h"
|
||||
#include "port_cube_ids.h"
|
||||
#include "../../common/cube_item_ids.h"
|
||||
|
||||
namespace {
|
||||
// A synchronous, non-reentrant bridge into the existing member's private ID
|
||||
// cursor. No callbacks/event dispatch occur before this scope is cleared.
|
||||
struct CubeIDRequest {
|
||||
unsigned count;
|
||||
std::vector<uint32_t> ids;
|
||||
};
|
||||
CubeIDRequest* cubeIDRequest=nullptr;
|
||||
struct CubeIDScope {
|
||||
explicit CubeIDScope(CubeIDRequest& request){cubeIDRequest=&request;}
|
||||
~CubeIDScope(){cubeIDRequest=nullptr;}
|
||||
};
|
||||
}
|
||||
|
||||
bool PortCubeReserveItemIDs(unsigned count,std::vector<uint32_t>& ids)
|
||||
{
|
||||
if(!count||count>100||cubeIDRequest)return false;
|
||||
CubeIDRequest request{count,{}};
|
||||
CubeIDScope scope(request);
|
||||
if(!ITEM_MANAGER::instance().GetNewID()||request.ids.size()!=count)return false;
|
||||
ids.swap(request.ids);
|
||||
return true;
|
||||
}
|
||||
|
||||
int touch(const char *path)
|
||||
{
|
||||
@@ -19,6 +45,28 @@ int touch(const char *path)
|
||||
|
||||
DWORD ITEM_MANAGER::GetNewID()
|
||||
{
|
||||
if(cubeIDRequest)
|
||||
{
|
||||
PortCube::ItemIDPlan plan;
|
||||
const PortCube::ItemIDRange active{m_ItemIDRange.dwMin,m_ItemIDRange.dwMax,m_ItemIDRange.dwUsableItemIDMin};
|
||||
const PortCube::ItemIDRange spare{m_ItemIDSpareRange.dwMin,m_ItemIDSpareRange.dwMax,m_ItemIDSpareRange.dwUsableItemIDMin};
|
||||
if(!PortCube::PlanItemIDs(active,m_dwCurrentID,spare,cubeIDRequest->count,plan))return 0;
|
||||
for(auto id:plan.ids)if(m_map_pkItemByID.find(id)!=m_map_pkItemByID.end())return 0;
|
||||
if(plan.spare&&!db_clientdesc)return 0;
|
||||
const DWORD oldMaximum=m_ItemIDRange.dwMax;
|
||||
if(plan.spare)
|
||||
{
|
||||
m_ItemIDRange=m_ItemIDSpareRange;
|
||||
m_ItemIDSpareRange.dwMin=0;
|
||||
m_ItemIDSpareRange.dwMax=0;
|
||||
m_ItemIDSpareRange.dwUsableItemIDMin=0;
|
||||
}
|
||||
m_dwCurrentID=plan.next;
|
||||
cubeIDRequest->ids.swap(plan.ids);
|
||||
// The reservation is already consumed before requesting another spare.
|
||||
if(plan.spare)db_clientdesc->DBPacket(HEADER_GD_REQ_SPARE_ITEM_ID_RANGE,0,&oldMaximum,sizeof(DWORD));
|
||||
return cubeIDRequest->ids.front();
|
||||
}
|
||||
assert(m_dwCurrentID != 0);
|
||||
|
||||
if ( m_dwCurrentID >= m_ItemIDRange.dwMax )
|
||||
|
||||
@@ -244,6 +244,12 @@ bool ITEM_MANAGER::ReadSpecialDropItemFile(const char * c_pszFileName)
|
||||
{
|
||||
dwVnum = CSpecialItemGroup::POISON;
|
||||
}
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
else if (name == "bleeding")
|
||||
{
|
||||
dwVnum = CSpecialItemGroup::BLEEDING;
|
||||
}
|
||||
#endif
|
||||
else if (name == "group")
|
||||
{
|
||||
dwVnum = CSpecialItemGroup::MOB_GROUP;
|
||||
@@ -378,6 +384,9 @@ bool ITEM_MANAGER::ConvSpecialDropItemFile()
|
||||
name == "slow" ||
|
||||
name == "drain_hp" ||
|
||||
name == "poison" ||
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
name == "bleeding" ||
|
||||
#endif
|
||||
name == "group")
|
||||
{
|
||||
dwVnum = 0;
|
||||
|
||||
@@ -1034,11 +1034,13 @@ static void __LocaleService_Init_Taiwan()
|
||||
|
||||
static void __CheckPlayerSlot(const std::string& service_name)
|
||||
{
|
||||
#ifndef ENABLE_PLAYER_PER_ACCOUNT5
|
||||
if (PLAYER_PER_ACCOUNT != 4)
|
||||
{
|
||||
printf("<ERROR> PLAYER_PER_ACCOUNT = %d\n", PLAYER_PER_ACCOUNT);
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool LocaleService_Init(const std::string& c_rstServiceName)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "new_mob_timer.h"
|
||||
#include "port_cube_actor.h"
|
||||
#include "port_cube_recovery.h"
|
||||
#include "constants.h"
|
||||
#include "config.h"
|
||||
#include "event.h"
|
||||
@@ -31,6 +33,10 @@
|
||||
#include "cmd.h"
|
||||
#include "refine.h"
|
||||
#include "banword.h"
|
||||
|
||||
#ifndef __FreeBSD__
|
||||
static int optreset;
|
||||
#endif
|
||||
#include "priv_manager.h"
|
||||
#include "war_map.h"
|
||||
#include "building.h"
|
||||
@@ -723,7 +729,7 @@ int start(int argc, char **argv)
|
||||
std::string st_localeServiceName;
|
||||
|
||||
bool bVerbose = false;
|
||||
char ch;
|
||||
int ch;
|
||||
|
||||
//_malloc_options = "A";
|
||||
#if defined(__FreeBSD__) && defined(DEBUG_ALLOC)
|
||||
@@ -970,6 +976,8 @@ int idle()
|
||||
|
||||
t = get_dword_time();
|
||||
CHARACTER_MANAGER::instance().Update(thecore_heart->pulse);
|
||||
PortCubeActorTick();
|
||||
PortCubeRecoveryTick();
|
||||
db_clientdesc->Update(t);
|
||||
s_dwProfiler[PROF_CHR_UPDATE] += (get_dword_time() - t);
|
||||
|
||||
|
||||
@@ -272,7 +272,10 @@ bool CMotionManager::Build()
|
||||
"data/pc2/warrior",
|
||||
"data/pc2/assassin",
|
||||
"data/pc2/sura",
|
||||
"data/pc2/shaman"
|
||||
"data/pc2/shaman",
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
"data/pc3/wolfman",
|
||||
#endif
|
||||
};
|
||||
|
||||
for (int i = 0; i < MAIN_RACE_MAX_NUM; ++i)
|
||||
@@ -321,6 +324,12 @@ bool CMotionManager::Build()
|
||||
pkMotionSet->Load(sz, MOTION_MODE_HORSE, MOTION_RUN);
|
||||
snprintf(sz, sizeof(sz), "%s/horse/walk.msa", c_apszFolderName[i]);
|
||||
pkMotionSet->Load(sz, MOTION_MODE_HORSE, MOTION_WALK);
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
snprintf(sz, sizeof(sz), "%s/claw/run.msa", c_apszFolderName[i]);
|
||||
pkMotionSet->Load(sz, MOTION_MODE_CLAW, MOTION_RUN);
|
||||
snprintf(sz, sizeof(sz), "%s/claw/walk.msa", c_apszFolderName[i]);
|
||||
pkMotionSet->Load(sz, MOTION_MODE_CLAW, MOTION_WALK);
|
||||
#endif
|
||||
}
|
||||
|
||||
CMobManager::iterator it = CMobManager::instance().begin();
|
||||
|
||||
@@ -13,6 +13,9 @@ enum EMotionMode
|
||||
MOTION_MODE_BELL,
|
||||
MOTION_MODE_FAN,
|
||||
MOTION_MODE_HORSE,
|
||||
#ifdef ENABLE_WOLFMAN_CHARACTER
|
||||
MOTION_MODE_CLAW,
|
||||
#endif
|
||||
MOTION_MODE_MAX_NUM
|
||||
};
|
||||
|
||||
|
||||
@@ -122,6 +122,7 @@ enum
|
||||
HEADER_CG_STATE_CHECKER = 206,
|
||||
HEADER_CG_SASH = 211, // AVA2 sash
|
||||
HEADER_CG_AVA2_DROP = 215,
|
||||
HEADER_CG_CUBE_RENEWAL = 216, // AVA2 cuberenewal (port_cube_renewal.inc)
|
||||
HEADER_CG_ITEMS_PICKUP = 235, // PORT: AVA2
|
||||
HEADER_CG_SWITCHBOT = 171, // AVA2 switchbot (port_switchbot.cpp)
|
||||
|
||||
@@ -320,12 +321,17 @@ enum
|
||||
|
||||
HEADER_GC_SPECIFIC_EFFECT = 208,
|
||||
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
HEADER_GC_SUNGMA_ATTR_UPDATE = 231,
|
||||
#endif
|
||||
HEADER_GC_DRAGON_SOUL_REFINE = 209,
|
||||
HEADER_GC_RESPOND_CHANNELSTATUS = 210,
|
||||
HEADER_GC_SASH = 215, // AVA2 sash
|
||||
HEADER_GC_CHESTDROP = 66, // PORT: AVA2, DWORD dynamic length
|
||||
HEADER_GC_SWITCHBOT = 171, // AVA2 switchbot (port_switchbot.cpp)
|
||||
HEADER_GC_EXTENDED_POINTS = 218, // PORT: AVA2 64-bit gold
|
||||
HEADER_GC_CUBE_RENEWAL = 221, // AVA2 cuberenewal (port_cube_renewal.inc)
|
||||
HEADER_GC_PORT_QUIVER = 219, // PORT: negotiated, transient actor arrow subtype.
|
||||
#if defined(__BL_67_ATTR__)
|
||||
HEADER_GC_OPEN_67_ATTR = 242,
|
||||
#endif
|
||||
@@ -742,7 +748,7 @@ typedef struct command_item_drop2
|
||||
BYTE header;
|
||||
TItemPos Cell;
|
||||
DWORD gold;
|
||||
BYTE count;
|
||||
WORD count;
|
||||
} TPacketCGItemDrop2;
|
||||
|
||||
typedef struct command_item_move
|
||||
@@ -750,7 +756,7 @@ typedef struct command_item_move
|
||||
BYTE header;
|
||||
TItemPos Cell;
|
||||
TItemPos CellTo;
|
||||
BYTE count;
|
||||
WORD count;
|
||||
} TPacketCGItemMove;
|
||||
|
||||
typedef struct command_item_pickup
|
||||
@@ -810,7 +816,7 @@ typedef struct command_shop_buy
|
||||
typedef struct command_shop_sell
|
||||
{
|
||||
BYTE pos;
|
||||
BYTE count;
|
||||
WORD count;
|
||||
} TPacketCGShopSell;
|
||||
|
||||
typedef struct command_shop
|
||||
@@ -838,6 +844,7 @@ enum
|
||||
EXCHANGE_SUBHEADER_CG_ELK_ADD, /* arg1 == amount of gold */
|
||||
EXCHANGE_SUBHEADER_CG_ACCEPT, /* arg1 == not used */
|
||||
EXCHANGE_SUBHEADER_CG_CANCEL, /* arg1 == not used */
|
||||
EXCHANGE_SUBHEADER_CG_CHEQUE_ADD, /* arg1 == amount of won (PORT) */
|
||||
};
|
||||
|
||||
typedef struct command_exchange
|
||||
@@ -1002,6 +1009,14 @@ enum ECharacterEquipmentPart
|
||||
CHR_EQUIPPART_NUM,
|
||||
};
|
||||
|
||||
struct TPacketGCQuiverState
|
||||
{
|
||||
BYTE header;
|
||||
DWORD vid;
|
||||
BYTE type; // 0 none, 6 arrow, 9 quiver. No persistent character layout change.
|
||||
};
|
||||
static_assert(sizeof(TPacketGCQuiverState)==6,"quiver state wire size");
|
||||
|
||||
typedef struct packet_add_char
|
||||
{
|
||||
BYTE header;
|
||||
@@ -1030,6 +1045,9 @@ typedef struct packet_char_additional_info
|
||||
BYTE bEmpire;
|
||||
DWORD dwGuildID;
|
||||
DWORD dwLevel;
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
DWORD dwConquerorLevel;
|
||||
#endif
|
||||
short sAlignment;
|
||||
BYTE bPKMode;
|
||||
DWORD dwMountVnum;
|
||||
@@ -1069,6 +1087,9 @@ typedef struct packet_update_char
|
||||
|
||||
DWORD dwGuildID;
|
||||
short sAlignment;
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
DWORD dwConquerorLevel;
|
||||
#endif
|
||||
BYTE bPKMode;
|
||||
DWORD dwMountVnum;
|
||||
//WORD wRaceNum;
|
||||
@@ -1183,7 +1204,7 @@ struct TPacketGCItemDelDeprecated
|
||||
BYTE header;
|
||||
TItemPos Cell;
|
||||
DWORD vnum;
|
||||
BYTE count;
|
||||
WORD count;
|
||||
long alSockets[ITEM_SOCKET_MAX_NUM];
|
||||
TPlayerItemAttribute aAttr[ITEM_ATTRIBUTE_MAX_NUM];
|
||||
};
|
||||
@@ -1193,7 +1214,7 @@ typedef struct packet_item_set
|
||||
BYTE header;
|
||||
TItemPos Cell;
|
||||
DWORD vnum;
|
||||
BYTE count;
|
||||
WORD count;
|
||||
DWORD flags;
|
||||
DWORD anti_flags;
|
||||
bool highlight;
|
||||
@@ -1306,7 +1327,7 @@ typedef struct packet_item_update
|
||||
{
|
||||
BYTE header;
|
||||
TItemPos Cell;
|
||||
BYTE count;
|
||||
WORD count;
|
||||
long alSockets[ITEM_SOCKET_MAX_NUM];
|
||||
TPlayerItemAttribute aAttr[ITEM_ATTRIBUTE_MAX_NUM];
|
||||
} TPacketGCItemUpdate;
|
||||
@@ -1384,18 +1405,21 @@ enum EPacketShopSubHeaders
|
||||
SHOP_SUBHEADER_GC_REFRESH_COUNT,
|
||||
SHOP_SUBHEADER_GC_CHANGE_TITLE,
|
||||
#endif
|
||||
// PORT: Won prices for mt>=20261027 clients; START_CHEQUE = START + int32 cheque[SHOP_HOST_ITEM_MAX_NUM].
|
||||
SHOP_SUBHEADER_GC_START_CHEQUE = 40,
|
||||
SHOP_SUBHEADER_GC_NOT_ENOUGH_CHEQUE = 41,
|
||||
};
|
||||
|
||||
struct packet_shop_item
|
||||
{
|
||||
DWORD vnum;
|
||||
int64_t price;
|
||||
BYTE count;
|
||||
WORD count;
|
||||
BYTE display_pos;
|
||||
int32_t alSockets[ITEM_SOCKET_MAX_NUM];
|
||||
TPlayerItemAttribute aAttr[ITEM_ATTRIBUTE_MAX_NUM];
|
||||
};
|
||||
static_assert(sizeof(packet_shop_item)==47,"gold64 shop item wire size");
|
||||
static_assert(sizeof(packet_shop_item)==48,"gold64 shop item wire size");
|
||||
|
||||
typedef struct packet_shop_start
|
||||
{
|
||||
@@ -1456,6 +1480,8 @@ enum EPacketTradeSubHeaders
|
||||
EXCHANGE_SUBHEADER_GC_END, /* arg1 == not used */
|
||||
EXCHANGE_SUBHEADER_GC_ALREADY, /* arg1 == not used */
|
||||
EXCHANGE_SUBHEADER_GC_LESS_GOLD, /* arg1 == not used */
|
||||
EXCHANGE_SUBHEADER_GC_CHEQUE_ADD, /* arg1 == won (PORT) */
|
||||
EXCHANGE_SUBHEADER_GC_LESS_CHEQUE, /* arg1 == not used */
|
||||
};
|
||||
|
||||
struct packet_position
|
||||
@@ -2040,7 +2066,7 @@ typedef struct command_give_item
|
||||
BYTE byHeader;
|
||||
DWORD dwTargetVID;
|
||||
TItemPos ItemPos;
|
||||
BYTE byItemCount;
|
||||
WORD byItemCount;
|
||||
} TPacketCGGiveItem;
|
||||
|
||||
typedef struct SPacketCGHack
|
||||
@@ -2292,7 +2318,7 @@ typedef struct pakcet_view_equip
|
||||
DWORD vid;
|
||||
struct {
|
||||
DWORD vnum;
|
||||
BYTE count;
|
||||
WORD count;
|
||||
long alSockets[ITEM_SOCKET_MAX_NUM];
|
||||
TPlayerItemAttribute aAttr[ITEM_ATTRIBUTE_MAX_NUM];
|
||||
} equips[WEAR_MAX_NUM];
|
||||
@@ -2347,6 +2373,17 @@ typedef struct
|
||||
BYTE bApplyOn;
|
||||
} TPacketGCAffectRemove;
|
||||
|
||||
#ifdef ENABLE_CONQUEROR_LEVEL
|
||||
typedef struct packet_sungma_attr_update
|
||||
{
|
||||
BYTE bHeader;
|
||||
BYTE bSTR;
|
||||
BYTE bHP;
|
||||
BYTE bMOVE;
|
||||
BYTE bINMUNE;
|
||||
} TPacketGCSungmaAttrUpdate;
|
||||
#endif
|
||||
|
||||
typedef struct packet_lover_info
|
||||
{
|
||||
BYTE header;
|
||||
@@ -2672,7 +2709,55 @@ struct TPacketGCExtendedPointGold
|
||||
int64_t gold;
|
||||
};
|
||||
static_assert(sizeof(TPacketGCExtendedPointGold) == 10, "TPacketGCExtendedPointGold size mismatch");
|
||||
// AVA2 ENABLE_CUBE_RENEWAL_WORLDARD, byte-identical to the AVA2 client.
|
||||
enum ECubeRenewalSubHeader
|
||||
{
|
||||
CUBE_RENEWAL_SUB_HEADER_OPEN_RECEIVE,
|
||||
CUBE_RENEWAL_SUB_HEADER_CLEAR_DATES_RECEIVE,
|
||||
CUBE_RENEWAL_SUB_HEADER_DATES_RECEIVE,
|
||||
CUBE_RENEWAL_SUB_HEADER_DATES_LOADING,
|
||||
CUBE_RENEWAL_SUB_HEADER_MAKE_ITEM,
|
||||
CUBE_RENEWAL_SUB_HEADER_CLOSE,
|
||||
};
|
||||
struct TPacketCGCubeRenewalSend
|
||||
{
|
||||
uint8_t header;
|
||||
uint8_t subheader;
|
||||
uint32_t index_item;
|
||||
uint32_t count_item;
|
||||
};
|
||||
struct TInfoDateCubeRenewal
|
||||
{
|
||||
uint32_t npc_vnum;
|
||||
uint32_t index;
|
||||
uint32_t vnum_reward;
|
||||
int32_t count_reward;
|
||||
bool item_reward_stackable;
|
||||
uint32_t vnum_material_1; int32_t count_material_1;
|
||||
uint32_t vnum_material_2; int32_t count_material_2;
|
||||
uint32_t vnum_material_3; int32_t count_material_3;
|
||||
uint32_t vnum_material_4; int32_t count_material_4;
|
||||
uint32_t vnum_material_5; int32_t count_material_5;
|
||||
int32_t gold;
|
||||
int32_t percent;
|
||||
char category[100];
|
||||
};
|
||||
struct TPacketGCCubeRenewalReceive
|
||||
{
|
||||
uint8_t header;
|
||||
uint8_t subheader;
|
||||
TInfoDateCubeRenewal date_cube_renewal;
|
||||
};
|
||||
static_assert(sizeof(TPacketCGCubeRenewalSend)==10,"AVA2 CG216 size");
|
||||
static_assert(sizeof(TPacketGCCubeRenewalReceive)==167,"AVA2 GC221 size");
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack()
|
||||
#endif
|
||||
|
||||
// PORT mt20261030: actual item quantities are uint16 on the client wire.
|
||||
static_assert(sizeof(TPacketCGItemMove) == 9, "wide item move");
|
||||
static_assert(sizeof(TPacketCGItemDrop2) == 10, "wide item drop");
|
||||
static_assert(sizeof(TPacketCGGiveItem) == 10, "wide give item");
|
||||
static_assert(sizeof(TPacketGCItemSet) == 52, "wide item set");
|
||||
static_assert(sizeof(TPacketGCItemUpdate) == 39, "wide item update");
|
||||
|
||||
@@ -232,6 +232,7 @@ CPacketInfoCG::CPacketInfoCG()
|
||||
Set(HEADER_CG_SASH, sizeof(TPacketSash), "Sash", true);
|
||||
Set(HEADER_CG_ITEMS_PICKUP,sizeof(TPacketCGItemsPickUp),"ItemsPickup",true);
|
||||
Set(HEADER_CG_AVA2_DROP,sizeof(TPacketCGAva2Drop),"Ava2Drop",true);
|
||||
Set(HEADER_CG_CUBE_RENEWAL,sizeof(TPacketCGCubeRenewalSend),"CubeRenewal",true);
|
||||
Set(HEADER_CG_SWITCHBOT, sizeof(TPacketCGSwitchbot), "Switchbot", true);
|
||||
#if defined(__BL_67_ATTR__)
|
||||
Set(HEADER_CG_67_ATTR, sizeof(TPacketCG67Attr), "67Attr", true);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// PORT: battle pass, game side (port_battlepass.h has the config and state). Protocol: docs/FEATURE-BATTLEPASS.md.
|
||||
// Included once, by cmd_general.cpp; the hooks in other files go through port_battlepass_hooks.h.
|
||||
#include <map>
|
||||
#include "port_material_stack_policy.h"
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@@ -215,7 +216,7 @@ inline const char* PortBpStacks(const std::vector<PortBpReward>& rewards,std::ve
|
||||
if(!table || table->bType==ITEM_DS || !table->bSize || table->bSize>3)return "config";
|
||||
const bool stackable=IS_SET(table->dwFlags,ITEM_FLAG_STACKABLE) && !IS_SET(table->dwAntiFlags,ITEM_ANTIFLAG_STACK);
|
||||
for(unsigned left=r.count;left;) {
|
||||
const unsigned count=stackable?std::min<unsigned>(left,ITEM_MAX_COUNT):1;
|
||||
const unsigned count=stackable?std::min<unsigned>(left,PortMaterialStackPolicy::Limit(table->bType,true,false,r.vnum)):1;
|
||||
stacks.push_back(PortBpStack{r.vnum,count,table->bSize});left-=count;
|
||||
if(stacks.size()>kPortBpMaxStacks)return "config";
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user