mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-15 14:39:50 +00:00
Server update 0.63.5
- async lua implementation - cleaner backend heartbeat - two way encryption on connect - async tcp buffer - disconnect handler - cleaned UDP implementation
This commit is contained in:
42
include/Buffer.h
Normal file
42
include/Buffer.h
Normal file
@@ -0,0 +1,42 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 8/25/2020
|
||||
///
|
||||
#pragma once
|
||||
#include <mutex>
|
||||
class Client;
|
||||
void GParser(Client*c, const std::string&Packet);
|
||||
class Buffer{
|
||||
public:
|
||||
void Handle(Client*c,const std::string& Data){
|
||||
if(c == nullptr)return;
|
||||
Buf += Data;
|
||||
Manage(c);
|
||||
}
|
||||
void clear(){
|
||||
Buf.clear();
|
||||
}
|
||||
private:
|
||||
std::string Buf;
|
||||
void Manage(Client*c){
|
||||
if(!Buf.empty()){
|
||||
std::string::size_type p;
|
||||
if (Buf.at(0) == '\n'){
|
||||
p = Buf.find('\n',1);
|
||||
if(p != -1){
|
||||
std::string R = Buf.substr(1,p-1);
|
||||
std::string_view B(R.c_str(),R.find(char(0)));
|
||||
GParser(c, B.data());
|
||||
Buf = Buf.substr(p+1);
|
||||
Manage(c);
|
||||
}
|
||||
}else{
|
||||
p = Buf.find('\n');
|
||||
if(p == -1)Buf.clear();
|
||||
else{
|
||||
Buf = Buf.substr(p);
|
||||
Manage(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user