Add check if connected and remove block list and removing of old data.
This commit is contained in:
parent
1516ad63cb
commit
31e8f302ac
@ -42,4 +42,6 @@ private:
|
||||
Rectangle genTextBox;
|
||||
Rectangle simTextBox;
|
||||
float simil = 100.0f;
|
||||
|
||||
Color appColor = BLUE;
|
||||
};
|
||||
|
@ -7,4 +7,5 @@ namespace DnaStore
|
||||
void saveVec(DnaManagerData *data);
|
||||
void saveGen(DnaManagerData *data);
|
||||
void sync();
|
||||
bool ping();
|
||||
} // namespace DnaStore
|
||||
|
@ -114,6 +114,10 @@ void App::init(int screenWidth, int screenHeight)
|
||||
float recPosX = screenWidth * 0.3f;
|
||||
disLikeBox = {0, posY, (float)recPosX, (float)screenWidth};
|
||||
likeBox = {screenWidth - recPosX, posY, (float)recPosX, (float)screenWidth};
|
||||
|
||||
if(!DnaStore::ping()){
|
||||
appColor = RED;
|
||||
}
|
||||
}
|
||||
|
||||
void App::upTex(Liked liked)
|
||||
@ -202,7 +206,7 @@ void App::update()
|
||||
|
||||
void App::draw()
|
||||
{
|
||||
ClearBackground(BLUE);
|
||||
ClearBackground(appColor);
|
||||
|
||||
Rectangle source = {0, 0, (float)screenWidth, (float)-screenWidth};
|
||||
Vector2 origin = {0.0f, 0.0f};
|
||||
|
@ -161,6 +161,20 @@ void DnaStore::sync()
|
||||
t.detach();
|
||||
}
|
||||
|
||||
bool DnaStore::ping(){
|
||||
int sock = TcpSocket::connectt(HOST_NAME, keyPort);
|
||||
if (sock < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int64_t header = 0;
|
||||
TcpSocket::recvt(sock, &header, sizeof(header));
|
||||
TcpSocket::closet(sock);
|
||||
|
||||
return header == StartHeader;
|
||||
}
|
||||
|
||||
void client(std::string_view prefix)
|
||||
{
|
||||
constexpr int extra_buff = 22; // len of 2**31 -> 2147483648 plus the pattern size
|
||||
|
@ -89,11 +89,6 @@ BlockedList blockedList;
|
||||
// When a new client connected:
|
||||
void call(int sock, sockaddr_in newSocketInfo)
|
||||
{
|
||||
if (blockedList.isBlocked(newSocketInfo.sin_addr.s_addr))
|
||||
{
|
||||
TcpSocket::closet(sock);
|
||||
return;
|
||||
}
|
||||
std::string add = TcpSocket::remoteAddress(newSocketInfo);
|
||||
printf("new: %s\n", add.c_str());
|
||||
int64_t conf, id;
|
||||
@ -106,7 +101,7 @@ void call(int sock, sockaddr_in newSocketInfo)
|
||||
{
|
||||
printf("StartHeader ERROR\n");
|
||||
TcpSocket::closet(sock);
|
||||
blockedList.addWarning(newSocketInfo.sin_addr.s_addr);
|
||||
//blockedList.addWarning(newSocketInfo.sin_addr.s_addr);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -114,7 +109,7 @@ void call(int sock, sockaddr_in newSocketInfo)
|
||||
{
|
||||
printf("ID ERROR\n");
|
||||
TcpSocket::closet(sock);
|
||||
blockedList.addWarning(newSocketInfo.sin_addr.s_addr);
|
||||
//blockedList.addWarning(newSocketInfo.sin_addr.s_addr);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -216,7 +211,7 @@ int main()
|
||||
sql::init();
|
||||
sql::create_tables();
|
||||
blockedList.init();
|
||||
std::thread t(checker);
|
||||
//std::thread t(checker);
|
||||
std::thread l(listen_key);
|
||||
// Bind the server to a port.
|
||||
int err = TcpSocket::listent("0.0.0.0", serverPort, call);
|
||||
|
Loading…
x
Reference in New Issue
Block a user