lbMyWholeOch->Caption=MyWholeOch;
if (MyWholeOch>MaxOch)
{
lbMyWholeOch->Font->Color=clRed;
ViProigrali();
}
else if(IsHeFixed &&
MyWholeOch>HisWholeOch && MyWholeOch<=MaxOch)
{
ViViigrali();
}
else if(IsHeFixed &&
MyWholeOch<=HisWholeOch)
{
ChangeInterfacePerehodHoda(1);
}
else
{
ChangeInterfacePerehodHoda(0);
}
delete Bitmap1;
}
//---------------------------------------------------------------------------
void __fastcall
TMainForm::btFix2Click(TObject *Sender)
{
IsYaFixed=true;
if(IsServer)
{
NomHoda++;
}
btFix->Color=clRed;
btBrosit->Color=clCream;
lbMyWholeOch->Font->Color=clRed;
switch(choosenProt)
{
case 0:
IPXSend("2;");
break;
case 1:
TCPIPSend("2;");
break;
case 2:
NetBiosSend("2;");
break;
case 3:
MailSlotSend("2;");
break;
case 4:
PipeSend("2;");
break;
}
enum TypeDannihForTabl
DannieForTabl;
DannieForTabl=yafixed;
ZapolnTabl(DannieForTabl);
if(IsHeFixed &&
MyWholeOch==HisWholeOch)
{
Nichia();
}
else if(MyWholeOch<HisWholeOch)
{
ViProigrali();
}
else
{
ChangeInterfacePerehodHoda(0);
}
}
//---------------------------------------------------------------------------
Ipx.cpp
//---------------------------------------------------------------------------
#pragma hdrstop
#include <winsock.h>
#include <wsipx.h>
#include "IPX.h"
#include "Main.h"
#include "Podkluch.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#define IPX_SERVER_SOCKET 0x4504
#define IPX_CLIENT_SOCKET 0x4514
#define WSA_NETEVENT (WM_USER+2)
SOCKET IPXSocket;
sockaddr_ipx CallAddress;
sockaddr_ipx OurAddress;
extern bool IsServer;
extern int KolKub;
extern int MaxOch;
//-----------------------Ïîäêëþ÷åíèå--------------------------------------------
void __fastcall
TMainForm::IPXConnect(void)
{
WSADATA WSAData;
int rc, OptVal=1;
rc = WSAStartup(MAKEWORD(2,0),
&WSAData);
if (rc != 0)
{
Application->MessageBox("Îøèáêà èíèöèàëèçàöèè
WSAStartup","Îøèáêà",MB_OK+MB_ICONHAND);
Application->Terminate();
}
IPXSocket = socket(AF_IPX,
SOCK_DGRAM, NSPROTO_IPX);
if (IPXSocket == INVALID_SOCKET)
{
Application->MessageBox("Ïðîòîêîë IPX íå
óñòàíîâëåí","Îøèáêà",MB_OK+MB_ICONHAND);
Application->Terminate();
}
memset(&OurAddress, 0,
sizeof(OurAddress));
OurAddress.sa_family = AF_IPX;
if(IsServer)
OurAddress.sa_socket =
htons((unsigned short)(IPX_SERVER_SOCKET));
else
OurAddress.sa_socket =
htons((unsigned short)(IPX_CLIENT_SOCKET));
if (bind(IPXSocket,
(LPSOCKADDR)&OurAddress, sizeof(sockaddr_ipx)) == SOCKET_ERROR)
{
Application->MessageBox("Àäðåñíàÿ îøèáêà
IPX","Îøèáêà",MB_OK+MB_ICONHAND);
closesocket(IPXSocket);
IPXSocket = INVALID_SOCKET;
Application->Terminate();
}
rc = setsockopt(IPXSocket,
SOL_SOCKET, SO_BROADCAST, (char *)&OptVal, sizeof(OptVal));
if (rc == SOCKET_ERROR)
{
rc = WSAGetLastError();
Application->MessageBox("Îøèáêà
setsockopt","Îøèáêà",MB_OK+MB_ICONHAND);
closesocket(IPXSocket);
IPXSocket = INVALID_SOCKET;
Application->Terminate();
}
if(!IsServer)
{
memset(&CallAddress, 0,
sizeof(CallAddress));
CallAddress.sa_family =
AF_IPX;
CallAddress.sa_socket =
htons(IPX_SERVER_SOCKET);
CallAddress.sa_nodenum[0] =
0xff;
CallAddress.sa_nodenum[1] =
0xff;
CallAddress.sa_nodenum[2] =
0xff;
CallAddress.sa_nodenum[3] =
0xff;
CallAddress.sa_nodenum[4] =
0xff;
CallAddress.sa_nodenum[5] =
0xff;
rc = sendto(IPXSocket,
"connect", 8, 0, (PSOCKADDR)&CallAddress, sizeof(SOCKADDR));
if (rc == SOCKET_ERROR)
{
rc = WSAGetLastError();
Application->MessageBox("Îøèáêà sendto IPX","Îøèáêà",MB_OK+MB_ICONHAND);
closesocket(IPXSocket);
IPXSocket =
INVALID_SOCKET;
Application->Terminate();
}
}
rc = WSAAsyncSelect(IPXSocket,
Handle, WSA_NETEVENT, FD_READ);
if (rc != 0)
{
Application->MessageBox("Îøèáêà
WSAAsyncSelect","Îøèáêà",MB_OK+MB_ICONHAND);
closesocket(IPXSocket);
IPXSocket = INVALID_SOCKET;
Application->Terminate();
}
WindowProc = IPXWndProc;
}
//------------------------------ïðèåì---------------------------------------
void __fastcall
TMainForm::IPXWndProc(Messages::TMessage &Message)
{
int rc, l=sizeof(CallAddress);
char Buf[80];
if (Message.Msg == WSA_NETEVENT)
{
if (Message.LParam ==
FD_READ)
{
rc =
recvfrom((SOCKET)Message.WParam, Buf, sizeof(Buf)-1, 0,
(PSOCKADDR)&CallAddress, &l);
if (rc == SOCKET_ERROR)
{
rc =
WSAGetLastError();
Application->MessageBox("Îøèáêà recvfrom IPX","Îøèáêà",MB_OK+MB_ICONHAND);
closesocket(IPXSocket);
IPXSocket =
INVALID_SOCKET;
Application->Terminate();
}
if (rc >= 1)
{
if(!strcmp(Buf,"connect"))
{
char
*strPered=DannieToChar(0,KolKub,MaxOch);
IPXSend(strPered);
InterfaceBeginNewGame();
ChangeInterfacePerehodHoda(1);
}
else
{
if(IsVisitApplicationBox) return;
Priem(CharToMas(Buf));
}
}
}
}
WndProc(Message);
}
//-------------------------îòïðàâêà---------------------------------------------
void __fastcall TMainForm::IPXSend
(char* Buf)
{
int rc;
rc = sendto(IPXSocket, Buf,
strlen(Buf)+1, 0, (PSOCKADDR)&CallAddress, sizeof(SOCKADDR));
if (rc == SOCKET_ERROR)
{
rc = WSAGetLastError();
Application->MessageBox("Îøèáêà sendto
IPX","Îøèáêà",MB_OK+MB_ICONHAND);
closesocket(IPXSocket);
IPXSocket = INVALID_SOCKET;
Application->Terminate();
}
}
//-------------------------ðàçðûâ---------------------------------------------
void __fastcall
TMainForm::IPXCloseConnection(void)
{
closesocket(IPXSocket);
WSACleanup();
}
TCP.cpp
//---------------------------------------------------------------------------
#pragma hdrstop
#include "TCPIP.h"
#include "Main.h"
#include "Podkluch.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
extern bool IsServer;
extern bool IsHostName;
extern AnsiString ServerHostName;
extern AnsiString ServerHostIP;
extern int KolKub;
extern int MaxOch;
//----------Ïîäêëþ÷åíèå---------------------------------------------------
void __fastcall
TMainForm::TCPIPConnect(void)
{
if (IsServer==true)
{
ClientSocket1->Close();
ServerSocket1->Open();
}
else
{
ServerSocket1->Close();
if (IsHostName)
ClientSocket1->Host=ServerHostName;
else
ClientSocket1->Host=ServerHostIP;
ClientSocket1->Open();
}
}
//---------Accept---------------------------------------------------------------
void __fastcall
TMainForm::ServerSocket1Accept(TObject *Sender,
TCustomWinSocket *Socket)
{
char
*strPered=DannieToChar(0,KolKub,MaxOch);
TCPIPSend(AnsiString(strPered));
InterfaceBeginNewGame();
ChangeInterfacePerehodHoda(1);
}
//----------Îòïðàâêà------------------------------------------------------------
void __fastcall
TMainForm::TCPIPSend(AnsiString strSend)
{
if(IsServer)
ServerSocket1->Socket->Connections[0]->SendText(strSend);
else
ClientSocket1->Socket->SendText(strSend);
}
//-------------Ïîëó÷åíèå--------------------------------------------------------
void __fastcall
TMainForm::ServerSocket1ClientRead(TObject *Sender,
TCustomWinSocket *Socket)
{
if(IsVisitApplicationBox) return;
AnsiString strPriem=Socket->ReceiveText();
Priem(CharToMas(strPriem.c_str()));
}
//---------------------------------------------------------------------------
void __fastcall
TMainForm::ServerSocket1ClientConnect(TObject *Sender,
TCustomWinSocket *Socket)
{
//
}
//---------------------------------------------------------------------------
void __fastcall
TMainForm::ClientSocket1Connect(TObject *Sender,
TCustomWinSocket *Socket)
{
//StatusBar1->Panels->Items[0]->Text
= "Connect to: " + Socket->RemoteHost;
}
//---------------------------------------------------------------------------
void __fastcall
TMainForm::ServerSocket1Listen(TObject *Sender,
TCustomWinSocket *Socket)
{
//StatusBar1->Panels->Items[0]->Text="Listening...";
}
//--------------Ðàçðûâ ñîåäèíåíèÿ-------------------------------------------
void __fastcall
TMainForm::TCPIPCloseConnection(void)
{
ServerSocket1->Close();
ClientSocket1->Close();
}
//-----------Îáðàáîòêà
îøèáîê---------------------------------------------------
void __fastcall
TMainForm::ClientSocket1Error(TObject *Sender,
TCustomWinSocket *Socket,
TErrorEvent ErrorEvent, int &ErrorCode)
{
if(ErrorEvent==eeConnect)
{
ErrorCode=0;
Application->MessageBox("Íå óäàëîñü îñóùåñòâèòü ñîåäèíåíèå ñ
ñåðâåðîì.\nÓáåäèòåñü, ÷òî ñåðâåð îæèäàåò çàïðîñà
êëèåíòà.","Îøèáêà",MB_OK+MB_ICONHAND);
}
else
{
Application->MessageBox("Îøèáêà
TCP/IP","Îøèáêà",MB_OK+MB_ICONHAND);
Application->Terminate();
}
}
void __fastcall
TMainForm::ServerSocket1ClientError(TObject *Sender,
TCustomWinSocket *Socket,
TErrorEvent ErrorEvent, int &ErrorCode)
{
//
}
//-----------------------------------------------------------------------------
Netbios.cpp
//---------------------------------------------------------------------------
#pragma hdrstop
#include <winsock.h>
#include <wsnetbs.h>
#include <stdio.h>
#include "NetBios.h"
#include "Main.h"
#include "Podkluch.h"
#define NETBIOS_SERVER_NAME
"Kosti Server "
#define NETBIOS_CLIENT_NAME
"Kosti Client "
#define WSA_ACCEPT (WM_USER + 1)
#define WSA_NETEVENT (WM_USER+2)
//---------------------------------------------------------------------------
#pragma package(smart_init)
SOCKET NetBiosSocket;
sockaddr_nb OurAddress;
sockaddr_nb CallAddress;
extern bool IsServer;
extern int KolKub;
extern int MaxOch;
//----------------------------Ïîäêëþ÷åíèå---------------------------------------
void __fastcall
TMainForm::NetBiosConnect(void)
{
WSADATA WSAData;
int rc;
rc = WSAStartup(MAKEWORD(2,0),
&WSAData);
if (rc != 0)
{
Application->MessageBox("Îøèáêà èíèöèàëèçàöèè
WSAStartup","Îøèáêà",MB_OK+MB_ICONHAND);
Application->Terminate();
}
int Lana;
for (Lana=0;Lana<1000;Lana++)
{
NetBiosSocket =
socket(AF_NETBIOS, SOCK_SEQPACKET, -Lana);
if (NetBiosSocket ==
INVALID_SOCKET)
{
continue;
}
memset(&OurAddress, 0,
sizeof(OurAddress));
OurAddress.snb_family =
AF_NETBIOS;
OurAddress.snb_type =
NETBIOS_UNIQUE_NAME;
if(IsServer)
strcpy(OurAddress.snb_name,NETBIOS_SERVER_NAME);
else
strcpy(OurAddress.snb_name,NETBIOS_CLIENT_NAME);
if (bind(NetBiosSocket,
(LPSOCKADDR)&OurAddress, sizeof(sockaddr_nb)) == SOCKET_ERROR)
{
closesocket(NetBiosSocket);
NetBiosSocket =
INVALID_SOCKET;
continue;
}
else break;
}
if(Lana==1000)
{
Application->MessageBox("Íå îïðåäåëåíà
Lana","Îøèáêà",MB_OK+MB_ICONHAND);
Application->Terminate();
}
if(IsServer)
{
if(listen(NetBiosSocket, 1)
== SOCKET_ERROR )
{
Application->MessageBox("Listen
Error","Îøèáêà",MB_OK+MB_ICONHAND);
closesocket(NetBiosSocket);
Application->Terminate();
}
rc =
WSAAsyncSelect(NetBiosSocket, Handle, WSA_ACCEPT, FD_ACCEPT);
if (rc != 0)
{
Application->MessageBox("Îøèáêà
WSAAsyncSelect","Îøèáêà",MB_OK+MB_ICONHAND);
closesocket(NetBiosSocket);
NetBiosSocket =
INVALID_SOCKET;
Application->Terminate();
}
}
else
{
memset(&CallAddress, 0,
sizeof(CallAddress));
CallAddress.snb_family =
AF_NETBIOS;
CallAddress.snb_type =
NETBIOS_UNIQUE_NAME;
strcpy(CallAddress.snb_name,NETBIOS_SERVER_NAME);
if(connect(NetBiosSocket ,
(PSOCKADDR )&CallAddress, sizeof(CallAddress)) < 0)
{
Application->MessageBox("Connect
Error","Îøèáêà",MB_OK+MB_ICONHAND);
closesocket(NetBiosSocket);
Application->Terminate();
}
rc =
WSAAsyncSelect(NetBiosSocket, Handle, WSA_NETEVENT, FD_READ);
if (rc != 0)
{
Application->MessageBox("Îøèáêà
WSAAsyncSelect","Îøèáêà",MB_OK+MB_ICONHAND);
closesocket(NetBiosSocket);
NetBiosSocket =
INVALID_SOCKET;
Application->Terminate();
}
}
WindowProc = NetBiosWndProc;
}
//-------------------Ïðèåì è
accept---------------------------------------------
void __fastcall
TMainForm::NetBiosWndProc(Messages::TMessage &Message)
{
int rc;
char Buf[80];
if (Message.Msg == WSA_NETEVENT)
{
if (Message.LParam ==
FD_READ)
{
rc =
recv((SOCKET)Message.WParam, Buf, sizeof(Buf)-1, 0);
if (rc == SOCKET_ERROR)
{
rc =
WSAGetLastError();
Application->MessageBox("Îøèáêà recv
NetBios","Îøèáêà",MB_OK+MB_ICONHAND);
closesocket(NetBiosSocket);
NetBiosSocket =
INVALID_SOCKET;
Application->Terminate();
}
if (rc >= 1)
{
if(IsVisitApplicationBox)
return;
Priem(CharToMas(Buf));
}
}
}
else if(Message.Msg ==
WSA_ACCEPT)
{
if(Message.LParam ==
FD_ACCEPT)
{
int sizeCallAddress =
sizeof(CallAddress);
NetBiosSocket = accept
(NetBiosSocket, (LPSOCKADDR )&CallAddress, (int FAR
*)&sizeCallAddress);
if(NetBiosSocket ==
INVALID_SOCKET)
{
Application->MessageBox("Îøèáêà
Accept","Îøèáêà",MB_OK+MB_ICONHAND);
Application->Terminate();
}
char
*strPered=DannieToChar(0,KolKub,MaxOch);
NetBiosSend(strPered);
InterfaceBeginNewGame();
ChangeInterfacePerehodHoda(1);
rc = WSAAsyncSelect(NetBiosSocket,
Handle, WSA_NETEVENT, FD_READ);
if (rc != 0)
{
Application->MessageBox("Îøèáêà
WSAAsyncSelect","Îøèáêà",MB_OK+MB_ICONHAND);
closesocket(NetBiosSocket);
NetBiosSocket =
INVALID_SOCKET;
Application->Terminate();
}
}
}
WndProc(Message);
}
//-------------------îòïðàâêà---------------------------------------------------
void __fastcall
TMainForm::NetBiosSend(char *Buf)
{
int rc;
rc = send(NetBiosSocket, Buf,
strlen(Buf)+1, 0);
if (rc == SOCKET_ERROR)
{
rc = WSAGetLastError();
Application->MessageBox("Îøèáêà sendto
NetBios","Îøèáêà",MB_OK+MB_ICONHAND);
closesocket(NetBiosSocket);
NetBiosSocket =
INVALID_SOCKET;
Application->Terminate();
}
}
//----------------ðàçðûâ-------------------------------------------------------
void __fastcall
TMainForm::NetBiosCloseConnection(void)
{
closesocket(NetBiosSocket);
WSACleanup();
}
//---------------------------------------------------------------------------
Pipe.cpp
//---------------------------------------------------------------------------
#pragma hdrstop
#include <stdio.h>
#include <stdlib.h>
#include <StrUtils.hpp>
#include "Pipe.h"
#include "Main.h"
#include "Podkluch.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
HANDLE PipeReceiveHandle,
PipeSendHandle;
extern bool IsServer;
extern AnsiString ServerHostName;
extern int KolKub;
extern int MaxOch;
//-----------------------ïîäêëþ÷åíèå--------------------------------------------
void __fastcall
TMainForm::PipeConnect(void)
{
if(IsServer)
{
PipeReceiveHandle = CreateNamedPipe("\\\\.\\pipe\\pipe_s",
PIPE_ACCESS_INBOUND,
PIPE_TYPE_BYTE|PIPE_NOWAIT,
PIPE_UNLIMITED_INSTANCES,
1000, 1000, 5000, NULL);
if (PipeReceiveHandle ==
INVALID_HANDLE_VALUE)
{
Application->MessageBox("Îøèáêà ïðè ñîçäàíèè pipe íà
ñåðâåðå","Îøèáêà",MB_OK+MB_ICONHAND);
TimerPipe->Enabled =
false;
Application->Terminate();
}
TimerPipe->Enabled = true;
}
else
{
PipeReceiveHandle =
CreateNamedPipe("\\\\.\\pipe\\pipe_c", PIPE_ACCESS_INBOUND,
PIPE_TYPE_BYTE|PIPE_NOWAIT,
PIPE_UNLIMITED_INSTANCES,
1000, 1000, 5000, NULL);
if (PipeReceiveHandle ==
INVALID_HANDLE_VALUE)
{
Application->MessageBox("Îøèáêà ïðè ñîçäàíèè pipe íà
êëèåíòå","Îøèáêà",MB_OK+MB_ICONHAND);
TimerPipe->Enabled =
false;
Application->Terminate();
}
TimerPipe->Enabled = true;
char Buf[100];
sprintf(Buf,
"\\\\%s\\pipe\\pipe_s", ServerHostName.c_str());
PipeSendHandle = CreateFile(Buf,
GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (PipeSendHandle ==
INVALID_HANDLE_VALUE)
{
int rc;
rc=GetLastError(); //5 51
Application->MessageBox("Îøèáêà ïðè ïîäêëþ÷åíèè ê pipe íà
ñåðâåðå","Îøèáêà",MB_OK+MB_ICONHAND);
Application->Terminate();
}
char CompName[50];
unsigned long cnl = 50;
GetComputerName(CompName,
&cnl);
int i=StrLen(CompName);
if(i>=50)
{
CompName[49]='\0';
}
unsigned long cbWritten;
char BufExchange[100];
strcpy(BufExchange,"connect;");
strcat(BufExchange,CompName);
WriteFile(PipeSendHandle,
BufExchange, i+9, &cbWritten, NULL);
}
}
//---------------ïðèåì è
accept--------------------------------------
void __fastcall
TMainForm::TimerPipeTimer(TObject *Sender)
{
int Rc;
DWORD cbRead;
DWORD cbWritten;
char Buf[100];
ConnectNamedPipe(PipeReceiveHandle,
NULL);
Rc = GetLastError();
if (Rc == ERROR_PIPE_CONNECTED)
//535
{
if (ReadFile(PipeReceiveHandle,
Buf, sizeof(Buf)-1, &cbRead, NULL))
{
if(LeftStr(AnsiString(Buf),7)=="connect")
{
char *Buftmp;
char BufConnect[150];
Buftmp=AnsiStrScan(Buf,';');
Buftmp++;
sprintf(BufConnect,
"\\\\%s\\pipe\\pipe_c", Buftmp);
PipeSendHandle =
CreateFile(BufConnect, GENERIC_WRITE, FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, NULL);
if (PipeSendHandle ==
INVALID_HANDLE_VALUE)
{
Application->MessageBox("Îøèáêà ïðè ïîäêëþ÷åíèè ê pipe íà
êëèåíòå","Îøèáêà",MB_OK+MB_ICONHAND);
Application->Terminate();
}
char
*strPered=DannieToChar(0,KolKub,MaxOch);
PipeSend(strPered);
InterfaceBeginNewGame();
ChangeInterfacePerehodHoda(1);
}
else
{
if(IsVisitApplicationBox)
return;
Priem(CharToMas(Buf));
}
}
}
}
//-----------------îòïðàâêà-----------------------------------------------------
void __fastcall TMainForm::PipeSend
(char* Buf)
{
unsigned long cbWritten=0;
WriteFile(PipeSendHandle, Buf,
strlen(Buf)+1, &cbWritten,NULL);
}
//-------------------ðàçðûâ
ñîåäèíåíèÿ-----------------------------------------
void __fastcall
TMainForm::PipeCloseConnection(void)
{
CloseHandle(PipeSendHandle);
CloseHandle(PipeReceiveHandle);
TimerPipe->Enabled = false;
}
Mailslot.cpp
//---------------------------------------------------------------------------
#pragma hdrstop
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "MailSlot.h"
#include "Podkluch.h"
#include "Main.h"
//------------------------------------------------------------------------------
#pragma package(smart_init)
HANDLE ReceiveMailslotHandle,
SendMailslotHandle;
int HisPrevNomMessage=0;
int MyCurrNomMessage=0;
extern bool IsServer;
extern AnsiString ServerHostName;
extern int KolKub;
extern int MaxOch;
//-----------------------ïîäêëþ÷åíèå--------------------------------------------
void __fastcall TMainForm::MailSlotConnect(void)
{
if(IsServer)
{
ReceiveMailslotHandle =
CreateMailslot("\\\\.\\mailslot\\msserver", 0, MAILSLOT_WAIT_FOREVER,
NULL);
if (ReceiveMailslotHandle ==
INVALID_HANDLE_VALUE)
{
Application->MessageBox("Îøèáêà ïðè ñîçäàíèè
mailslot","Îøèáêà",MB_OK+MB_ICONHAND);
Application->Terminate();
}
TimerMailSlot->Enabled = true;
}
else
{
ReceiveMailslotHandle =
CreateMailslot("\\\\.\\mailslot\\msclient", 0, MAILSLOT_WAIT_FOREVER,
NULL);
if (ReceiveMailslotHandle ==
INVALID_HANDLE_VALUE)
{
Application->MessageBox("Îøèáêà ïðè ñîçäàíèè
mailslot","Îøèáêà",MB_OK+MB_ICONHAND);
Application->Terminate();
}
TimerMailSlot->Enabled = true;
char BufConnect[70];
sprintf(BufConnect, "\\\\%s\\mailslot\\msserver"
, ServerHostName.c_str());
SendMailslotHandle =
CreateFile(BufConnect, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0,
NULL);
if (SendMailslotHandle ==
INVALID_HANDLE_VALUE)
{
Application->MessageBox("Îøèáêà
ïðè îòêðûòèè mailslot","Îøèáêà",MB_OK+MB_ICONHAND);
Application->Terminate();
}
char CompName[50];
unsigned long cnl = 50;
GetComputerName(CompName,
&cnl);
int i=StrLen(CompName);
if(i>=50)
{
CompName[49]='\0';
}
unsigned long cbWritten;
char BufExchange[50];
MyCurrNomMessage=1;
strcpy(BufExchange,"1;");
strcat(BufExchange,CompName);
WriteFile(SendMailslotHandle,BufExchange, strlen(BufExchange)+1,
&cbWritten, NULL);
}
}
//-----------------------ïðèåì è
accept-----------------------------------------
void __fastcall
TMainForm::TimerMailSlotTimer(TObject *Sender)
{
if(IsVisitApplicationBox) return;
int rc;
unsigned long cbMessages,
cbMsgNumber, cbRead;
char *BufExchange;
rc =
GetMailslotInfo(ReceiveMailslotHandle, NULL, &cbMessages, &cbMsgNumber,
NULL);
if (!rc)
{
Application->MessageBox("Îøèáêà
GetMailslotInfo","Îøèáêà",MB_OK+MB_ICONHAND);
Application->Terminate();
}
if (cbMsgNumber == 0) return;
BufExchange = new char[cbMessages];
ZeroMemory(BufExchange, cbMessages);
if (ReadFile(ReceiveMailslotHandle,
BufExchange, cbMessages, &cbRead, NULL))
{
int HisCurrNomMessage;
char Buftmp[150];
strcpy(Buftmp,BufExchange);
HisCurrNomMessage=atoi(strtok(BufExchange,";"));
if(HisCurrNomMessage>HisPrevNomMessage)
{
HisPrevNomMessage=HisCurrNomMessage;
char *Buf;
Buf=AnsiStrScan(Buftmp,';');
Buf++;
if(IsServer &&
HisCurrNomMessage==1)
{
char BufConnect[100];
sprintf(BufConnect,
"\\\\%s\\mailslot\\msclient" , Buf);
SendMailslotHandle =
CreateFile(BufConnect, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0,
NULL);
if (SendMailslotHandle ==
INVALID_HANDLE_VALUE)
{
Application->MessageBox("Îøèáêà ïðè îòêðûòèè
mailslot","Îøèáêà",MB_OK+MB_ICONHAND);
Application->Terminate();
}
char
*strPered=DannieToChar(0,KolKub,MaxOch);
MailSlotSend(strPered);
InterfaceBeginNewGame();
ChangeInterfacePerehodHoda(1);
}
else
{
Priem(CharToMas(Buf));
}
}
}
delete [] BufExchange;
}
//------------------------îòïðàâêà----------------------------------------------
void __fastcall
TMainForm::MailSlotSend(char *Buf)
{
unsigned long cbWritten;
char BufExchange[100];
MyCurrNomMessage++;
itoa(MyCurrNomMessage,BufExchange,10);
strcat(BufExchange,";");
strcat(BufExchange,Buf);
WriteFile(SendMailslotHandle,
BufExchange, strlen(BufExchange)+1, &cbWritten, NULL);
}
//----------------------ðàçðûâ
ñîåäèíåíèÿ---------------------------------------
void __fastcall
TMainForm::MailSlotCloseConnection(void)
{
CloseHandle(SendMailslotHandle);
CloseHandle(ReceiveMailslotHandle);
TimerMailSlot->Enabled = false;
MyCurrNomMessage=0;
HisPrevNomMessage=0;
}
Ñòðàíèöû: 1, 2, 3, 4
|