Files
metin2-server/src/server/common/cube_drain.h
T

33 lines
1.6 KiB
C++

#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;}
};
}