, , ! Lcbclan.ru , , , ,

:

:

-

Ȕ

:

-423

..

.

.

:

..

, 2006


. 21 , 5 .


, . , . .


IPX

IPX , , . Novell NetWare IPX. SPX NETBIOS IPX .

IPX

. 2.

. 2. IPX

- . , . 2, (Data), . , - , .

, , . . , , Intel. . , , IBM-370 ( ). .

 

IPX/SPX

, , IPX SPX, - , . - API (Application Programm Interface - ).   API IPX/SPX.

"-"

- . , (serve - , server - ). , , .

. .

, , . , , .

-, , . -. - , . , - .

- , .

, - -, :

  ;

o  .

, IPX, API. , . , - - . ( ) . IPX, - . "-" , -. - , . ( , -). -. , - .

IPX.

, . . IPX ( ipx.exe ipxodi.exe), , , .

, , ECB (Event Control Block). ECB , .

ECB, IPX .

IPX, , , . , IPX . , , ECB . ECB .

TCP/IP

TCP/IP telnet, , , .


TCP

(/) ( ) . , , TCP-.

TCP-

TCP-

TCP TCP-.

TCP .

. , , .

, , , .


TCP-

TCP- ( 32- ):

0 () 4 8 12 16 20 24 28 31

 

Source Port Destination Port

 

Sequence Number

 

Acknowledgement Number

 

Offset Reserved Flags Window

 

Checksum Urgent Point

 

Options Padding

 

  Source Port Destination Port ( ). , , - . :

20 ftp-data ( ftp)
21 fpt ()
23 telnet
25 smtp
70 gopher
80 www-http

..

  Sequence Number .

  Acknowledgement Number

  Window

  Offset

  Flags , , , .

  Checksum : . . , , .

  Urgent Point .

Pipe

, FIFO ( ), .

, :

-  , ( , -).

-  ( ).

pipe:

int fd[2];

pipe(int *fd);

fd[0] -

fd[1] -


, ?

, 1 2 u-area , . , 1 2, ,

NetBios

NetBios OSI: , . , . NETBIOS , IPX SPX.

NETBIOS IBM (IBM PC LAN), Novell NetWare, Microsoft Windows for Workgroups . , NETBIOS, NETBIOS.

, NETBIOS Novell NetWare Microsoft Windows for Workgroups. NETBIOS, . NETBIOS , IPX SPX. , Novell NetWare NETBIOS, . , , .

IPX SPX , . 6 . 4 . IPX Novell.

NETBIOS . 16 . (permanent name), . NETBIOS ( ) . , . , .

NETBIOS . , .

(name number), .

, IPX/SPX NETBIOS, , NETBIOS . ( IPX SPX) ( IPX), , . , , .

NETBIOS IPX/SPX Novell . , , , , -.


MailSlot

Mailslot CreateMailslot. Mailslot. , , . Mailslot , - . CreateMailslot INVALID_HANDLE_VALUE. GetLastError.

Mailslot, . CreateFile. Mailslot , WriteFile.

Mailslot ReadFile. , Mailslot. , ReadFile . GetMailslotInfo. SetMailslotInfo Mailslot .


Main.cpp

#include <vcl.h>

#include <stdlib.h>

#include <StrUtils.hpp>

#pragma hdrstop

#include "Main.h"

#include "Podkluch.h"

#include "GameParam.h"

#include "About.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

#pragma link "LMDCustomBevelPanel"

#pragma link "LMDCustomControl"

#pragma link "LMDCustomPanel"

#pragma link "LMDSimplePanel"

#pragma link "LMDBackPanel"

#pragma link "LMDCustomParentPanel"

#pragma link "LMDBaseControl"

#pragma link "LMDBaseGraphicControl"

#pragma link "LMDBaseLabel"

#pragma link "LMDControl"

#pragma link "LMDCustomSimpleLabel"

#pragma link "LMDSimpleLabel"

#pragma link "lmdcont"

#pragma link "LMDCustomComponent"

#pragma link "LMDCustomStatusBar"

#pragma link "LMDStatusBar"

#pragma link "LMDCustomPanelFill"

#pragma link "LMDPanelFill"

#pragma link "LMDCustomScrollBox"

#pragma link "LMDListBox"

#pragma link "LMDCustomFormFill"

#pragma link "LMDFormFill"

#pragma link "LMDWndProcComponent"

#pragma link "LMDBaseShape"

#pragma link "LMDShapeControl"

#pragma link "LMDCustomLabel"

#pragma link "LMDDrawEdge"

#pragma link "LMDLabel"

#pragma link "LMDBaseImage"

#pragma link "LMDCustomGroupBox"

#pragma link "LMDCustomLImage"

#pragma link "LMDGraphicControl"

#pragma link "LMDGroupBox"

#pragma link "LMDLImage"

#pragma link "LMDBaseGraphicButton"

#pragma link "LMDCustomShapeButton"

#pragma link "LMDShapeButton"

#pragma resource "*.dfm"

TMainForm *MainForm;

extern bool IsServer;

extern AnsiString Protocoli[];

extern int KolKub;

extern int MaxOch;

extern int choosenProt;

extern AnsiString ServerHostName;

extern AnsiString ServerHostIP;

extern bool IsHostName;

extern bool IsIgrayut;

extern int NomHoda;

extern int MyCurOch;

extern int MyWholeOch;

extern int HisWholeOch;

extern bool IsYaFixed;

extern bool IsHeFixed;

extern int HisWinPoPartiam;

extern int MyWinPoPartiam;

extern int NomPartia;

int *MasPriem;

//---------------------------------------------------------------------------

__fastcall TMainForm::TMainForm(TComponent* Owner)

: TForm(Owner)

{

}

//---------------------------------------------------------------------------

void __fastcall TMainForm::FormCreate(TObject *Sender)

{

FirstTimeShow=true;

IsVisitApplicationBox=false;

}

//---------------------------------------------------------------------------

void __fastcall TMainForm::FormActivate(TObject *Sender)

{

if(FirstTimeShow)

{

FirstTimeShow=false;

InterfaceBezIgri();

menuBeginClick(this);

}

}

//---------------------------------------------------------------------------

void __fastcall TMainForm::menuBeginClick(TObject *Sender)

{

if (IsIgrayut)

{

menuStopClick(this);

if (IsIgrayut) return;

}

if (UstanParametrov()) // 2-

{

//--------

switch(choosenProt)

{

case 0:

IPXConnect();

break;

case 1:

TCPIPConnect();

break;

case 2:

NetBiosConnect();

break;

case 3:

MailSlotConnect();

break;

case 4:

PipeConnect();

break;

}

if(IsServer) lbStat->Caption=" ...";

}

}

//---------------------------------------------------------------------------

bool __fastcall TMainForm::UstanParametrov(void)

{

int md1,md2;

for(;;)

{

md1=FormParamConnect->ShowModal();

FormParamConnect->Close();

if (md1==mrOk)

{

if (IsServer)

{

md2=FormGameParam->ShowModal();

if (md2==mrOk) return 1;

else continue;

}

else return 1;

}

else return 0;

}

}

void __fastcall TMainForm::OtobrazhDannihSopernika(int *MasPriem)

{

Graphics::TBitmap *Bitmap2 = new Graphics::TBitmap();

AnsiString strCat;

if(IsServer)

{

strCat="_2";

}

else

{

strCat="";

}

if(KolKub==1)

{

Bitmap2->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(MasPriem[3])+strCat);

Kubiki2[0]->Picture->Bitmap=Bitmap2;

Kubiki2[0]->Left=MasPriem[4];

Kubiki2[0]->Top=MasPriem[5];

Kubiki2[0]->Visible=true;

}

else if (KolKub==2)

{

Bitmap2->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(MasPriem[3])+strCat);

Kubiki2[0]->Picture->Bitmap=Bitmap2;

Kubiki2[0]->Left=MasPriem[4];

Kubiki2[0]->Top=MasPriem[5];

Kubiki2[0]->Visible=true;

Bitmap2->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(MasPriem[6])+strCat);

Kubiki2[1]->Picture->Bitmap=Bitmap2;

Kubiki2[1]->Left=MasPriem[7];

Kubiki2[1]->Top=MasPriem[8];

Kubiki2[1]->Visible=true;

}

else if (KolKub==3)

{

Bitmap2->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(MasPriem[3])+strCat);

Kubiki2[0]->Picture->Bitmap=Bitmap2;

Kubiki2[0]->Left=MasPriem[4];

Kubiki2[0]->Top=MasPriem[5];

Kubiki2[0]->Visible=true;

Bitmap2->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(MasPriem[6])+strCat);

Kubiki2[1]->Picture->Bitmap=Bitmap2;

Kubiki2[1]->Left=MasPriem[7];

Kubiki2[1]->Top=MasPriem[8];

Kubiki2[1]->Visible=true;

Bitmap2->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(MasPriem[9])+strCat);

Kubiki2[2]->Picture->Bitmap=Bitmap2;

Kubiki2[2]->Left=MasPriem[10];

Kubiki2[2]->Top=MasPriem[11];

Kubiki2[2]->Visible=true;

}

else

{

Bitmap2->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(MasPriem[3])+strCat);

Kubiki2[0]->Picture->Bitmap=Bitmap2;

Kubiki2[0]->Left=MasPriem[4];

Kubiki2[0]->Top=MasPriem[5];

Kubiki2[0]->Visible=true;

Bitmap2->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(MasPriem[6])+strCat);

Kubiki2[1]->Picture->Bitmap=Bitmap2;

Kubiki2[1]->Left=MasPriem[7];

Kubiki2[1]->Top=MasPriem[8];

Kubiki2[1]->Visible=true;

Bitmap2->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(MasPriem[9])+strCat);

Kubiki2[2]->Picture->Bitmap=Bitmap2;

Kubiki2[2]->Left=MasPriem[10];

Kubiki2[2]->Top=MasPriem[11];

Kubiki2[2]->Visible=true;

Bitmap2->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(MasPriem[12])+strCat);

Kubiki2[3]->Picture->Bitmap=Bitmap2;

Kubiki2[3]->Left=MasPriem[13];

Kubiki2[3]->Top=MasPriem[14];

Kubiki2[3]->Visible=true;

}

HisWholeOch=MasPriem[2];

lbHisWholeOch->Caption=IntToStr(MasPriem[2]);

delete Bitmap2;

}

//----------- --------------------------------------------

void __fastcall TMainForm::Priem(int *MasPriem)

{

if(MasPriem[0]==0) //

{

AnsiString mess;

mess=" :\n : "+IntToStr(MasPriem[1])+"\n : "+IntToStr(MasPriem[2]);

IsVisitApplicationBox=true;

Application->MessageBoxA(mess.c_str()," ",MB_OK);

KolKub=MasPriem[1];

MaxOch=MasPriem[2];

InterfaceBeginNewGame();

ChangeInterfacePerehodHoda(0);

IsVisitApplicationBox=false;

}

else if (MasPriem[0]==1) //

{

shapeBrosil->Brush->Color=0x0000CE00;

OtobrazhDannihSopernika(MasPriem);

if(!IsServer)

{

NomHoda++;

}

enum TypeDannihForTabl DannieForTabl;

DannieForTabl=hebrosil;

ZapolnTabl(DannieForTabl);

if(IsYaFixed && HisWholeOch>MyWholeOch && HisWholeOch<=MaxOch)

{

ViProigrali();

}

else if (HisWholeOch>MaxOch)

{

lbHisWholeOch->Font->Color=clRed;

ViViigrali();

}

else if(IsYaFixed && HisWholeOch<=MyWholeOch)

{

ChangeInterfacePerehodHoda(0);

}

else

{

ChangeInterfacePerehodHoda(1);

}

}

else if (MasPriem[0]==2) //

{

IsHeFixed=true;

lbHisWholeOch->Font->Color=clRed;

shapeFixed->Brush->Color=0x000000CE;

if(!IsServer)

{

NomHoda++;

}

enum TypeDannihForTabl DannieForTabl;

DannieForTabl=hefixed;

ZapolnTabl(DannieForTabl);

if(IsYaFixed && MyWholeOch==HisWholeOch)

{

Nichia();

}

else if(MyWholeOch>HisWholeOch)

{

ViViigrali();

}

else

{

ChangeInterfacePerehodHoda(1);

}

}

else if (MasPriem[0]==3) //

{

IsVisitApplicationBox=true;

Application->MessageBoxA(" .\n ."," ",MB_OK);

switch(choosenProt)

{

case 0:

IPXCloseConnection();

break;

case 1:

TCPIPCloseConnection();

break;

case 2:

NetBiosCloseConnection();

break;

case 3:

MailSlotCloseConnection();

break;

case 4:

PipeCloseConnection();

break;

}

for (int i=0;i<KolKub;i++)

{

delete Kubiki1[i];

delete Kubiki2[i];

}

IsIgrayut=false;

InterfaceBezIgri();

IsVisitApplicationBox=false;

}

delete [] MasPriem;

}

//---------------- ----------------------------------

void __fastcall TMainForm::ZapolnTabl(enum TypeDannihForTabl DannieForTabl)

{

if(IsServer)

{

if(DannieForTabl==yabrosil)

{

listboxOchki->Items->Add(" "+IntToStr(NomHoda)+"; "+IntToStr(MyCurOch));

listboxOchki->TopIndex=NomHoda-1;

if(NomHoda==9)

{

listboxOchki->Width=236;

listboxOchki->Left=14;

}

}

else if (DannieForTabl==yafixed)

{

listboxOchki->Items->Add(" "+IntToStr(NomHoda)+"; 0");

listboxOchki->TopIndex=NomHoda-1;

if(NomHoda==9)

{

listboxOchki->Width=236;

listboxOchki->Left=14;

}

}

else if (DannieForTabl==hebrosil)

{

listboxOchki->SetItemPart(NomHoda-1,2," "+IntToStr(MasPriem[1]));

listboxOchki->TopIndex=NomHoda-1;

}

else

{

listboxOchki->SetItemPart(NomHoda-1,2," 0");

listboxOchki->TopIndex=NomHoda-1;

}

}

else

{

if(DannieForTabl==yabrosil)

{

listboxOchki->SetItemPart(NomHoda-1,1," "+IntToStr(MyCurOch));

listboxOchki->TopIndex=NomHoda-1;

}

else if (DannieForTabl==yafixed)

{

listboxOchki->SetItemPart(NomHoda-1,1," 0");

listboxOchki->TopIndex=NomHoda-1;

}

else if (DannieForTabl==hebrosil)

{

listboxOchki->Items->Add(" "+ IntToStr(NomHoda)+";; "+IntToStr(MasPriem[1]));

listboxOchki->TopIndex=NomHoda-1;

if(NomHoda==9)

{

listboxOchki->Width=236;

listboxOchki->Left=14;

}

}

else

{

listboxOchki->Items->Add(" "+ IntToStr(NomHoda)+";; 0");

listboxOchki->TopIndex=NomHoda-1;

if(NomHoda==9)

{

listboxOchki->Width=236;

listboxOchki->Left=14;

}

}

}

}

//--------------------------------------------------------------------

void __fastcall TMainForm::ViProigrali(void)

{

IsVisitApplicationBox=true;

HisWinPoPartiam++;

Application->MessageBoxA(" !\n !","",MB_OK+MB_ICONEXCLAMATION);

InterfaceIgraemDalshe();

IsVisitApplicationBox=false;

}

//---------------------------------

void __fastcall TMainForm::ViViigrali(void)

{

IsVisitApplicationBox=true;

MyWinPoPartiam++;

Application->MessageBoxA(" !\n !","!!",MB_OK+MB_ICONEXCLAMATION);

InterfaceIgraemDalshe();

IsVisitApplicationBox=false;

}

//----------------------------------

void __fastcall TMainForm::Nichia(void)

{

IsVisitApplicationBox=true;

MyWinPoPartiam++;

HisWinPoPartiam++;

Application->MessageBoxA(" !\n !","",MB_OK+MB_ICONEXCLAMATION);

InterfaceIgraemDalshe();

IsVisitApplicationBox=false;

}

//----------------------------------------------------------------------------

void __fastcall TMainForm::menuOProgrClick(TObject *Sender)

{

FormAbout->ShowModal();

}

//-------------------------------------------------------------------

void __fastcall TMainForm::InterfaceBezIgri(void)

{

MyWholeOch=0;

HisWholeOch=0;

MyCurOch=0;

NomHoda=0;

IsYaFixed=false;

IsHeFixed=false;

NomPartia=0;

MyWinPoPartiam=0;

HisWinPoPartiam=0;

ServerHostName="";

ServerHostIP="";

IsIgrayut=false;

menuStop->Enabled=false;

panParam->Visible=false;

lbNomPartia->Visible=false;

panSchetPoPartiam->Visible=false;

gbPole1->Top=15;

gbPole2->Top=15;

gbTabl->Top=15;

this->Height=400;

this->Caption=" ";

btBrosit->Enabled=false;

btFix->Enabled=false;

btBrosit->Color=clCream;

btFix->Color=clCream;

shapeBrosil->Brush->Color=clSilver;

shapeFixed->Brush->Color=clSilver;

shapeBrosil->Caption->Font->Color=clWhite;

shapeFixed->Caption->Font->Color=clWhite;

lbMyWholeOch->Caption="0";

lbHisWholeOch->Caption="0";

lbMaxOch2->Caption="";

listboxOchki->Clear();

listboxOchki->Width=218;

listboxOchki->Left=23;

AnsiString tmp=AnsiQuotedStr("-> ",'"');

lbStat->Caption=" "+tmp;

}

//--------------------------------------------------------------

void __fastcall TMainForm::InterfaceBeginNewGame(void)

{

menuStop->Enabled=true;

if(IsServer)

{

Caption=Caption+" ";

imStolServer->Parent=panPole1;

imStolClient->Parent=panPole2;

}

else

{

Caption=Caption+" ";

imStolClient->Parent=panPole1;

imStolServer->Parent=panPole2;

}

for (int i=0;i<KolKub;i++)

{

Kubiki1[i] = new TImage(this);

Kubiki1[i]->Parent=panPole1;

Kubiki1[i]->Transparent=true;

Kubiki2[i] = new TImage(this);

Kubiki2[i]->Parent=panPole2;

Kubiki2[i]->Transparent=true;

}

panParam->Visible=true;

lbNomPartia->Visible=true;

panSchetPoPartiam->Visible=true;

gbPole1->Top=80;

gbTabl->Top=80;

gbPole2->Top=80;

this->Height=470;

lbKolKub->Caption=IntToStr(KolKub);

lbMaxOch->Caption=IntToStr(MaxOch);

lbMaxOch2->Caption=IntToStr(MaxOch);

lbNomPartia->Caption=" 1";

lbSchetPoPartiam->Caption="0 : 0";

NomPartia=1;

IsIgrayut=true;

}

//---------------------------------------------------------

void __fastcall TMainForm::ChangeInterfacePerehodHoda(bool HozhuYa)

{

if(HozhuYa)

{

btBrosit->Enabled=true;

btFix->Enabled=true;

btBrosit->Color=clCream;

btFix->Color=clCream;

shapeBrosil->Caption->Font->Color=clWhite;

shapeFixed->Caption->Font->Color=clWhite;

lbStat->Caption=" ...";

if (MyWholeOch>MaxOch-KolKub)

{

IsVisitApplicationBox=true;

Application->MessageBoxA(" - !","",MB_OK+MB_ICONEXCLAMATION);

IsVisitApplicationBox=false;

}

}

else

{

btBrosit->Enabled=false;

btFix->Enabled=false;

shapeBrosil->Brush->Color=clSilver;

shapeFixed->Brush->Color=clSilver;

shapeBrosil->Caption->Font->Color=clBlack;

shapeFixed->Caption->Font->Color=clBlack;

lbStat->Caption=" ...";

}

}

//--------------------------------------------------------------------------

void __fastcall TMainForm::InterfaceIgraemDalshe(void)

{

NomPartia++;

MyWholeOch=0;

HisWholeOch=0;

MyCurOch=0;

NomHoda=0;

IsYaFixed=false;

IsHeFixed=false;

IsIgrayut=true;

lbNomPartia->Caption=" "+IntToStr(NomPartia);

lbSchetPoPartiam->Caption=IntToStr(MyWinPoPartiam)+" : "+IntToStr(HisWinPoPartiam);

listboxOchki->Clear();

listboxOchki->Width=218;

listboxOchki->Left=23;

lbMyWholeOch->Caption="0";

lbHisWholeOch->Caption="0";

lbMyWholeOch->Font->Color=clGreen;

lbHisWholeOch->Font->Color=clGreen;

btBrosit->Color=clCream;

btFix->Color=clCream;

shapeBrosil->Brush->Color=clSilver;

shapeFixed->Brush->Color=clSilver;

for (int i=0;i<KolKub;i++)

{

Kubiki1[i]->Visible=false;

Kubiki2[i]->Visible=false;

}

if(IsServer)

{

ChangeInterfacePerehodHoda(1);

}

else

{

ChangeInterfacePerehodHoda(0);

}

}

//----------------------- ---------------------------------------

void __fastcall TMainForm::menuStopClick(TObject *Sender)

{

IsVisitApplicationBox=true;

if(Application->MessageBoxA(" ?"," ",MB_YESNO)==IDYES)

{

for (int i=0;i<KolKub;i++)

{

delete Kubiki1[i];

delete Kubiki2[i];

}

switch(choosenProt)

{

case 0:

IPXSend("3;");

IPXCloseConnection();

break;

case 1:

TCPIPSend("3;");

TCPIPCloseConnection();

break;

case 2:

NetBiosSend("3;");

NetBiosCloseConnection();

break;

case 3:

MailSlotSend("3;");

MailSlotCloseConnection();

break;

case 4:

PipeSend("3;");

PipeCloseConnection();

break;

}

IsIgrayut=false;

InterfaceBezIgri();

}

IsVisitApplicationBox=false;

}

//---------------------------------------------------------------------------

void __fastcall TMainForm::menuQuitClick(TObject *Sender)

{

Close();

}

//---------------------------------------------------------------------------

void __fastcall TMainForm::FormCloseQuery(TObject *Sender, bool &CanClose)

{

if (IsIgrayut)

{

menuStopClick(this);

if(IsIgrayut) CanClose=false;

}

}

//------------------- ---------------------

char* __fastcall TMainForm::DannieToChar(int Type, int MyCurOch, int MyWholeOch,

int ZnachKub1,int XKub1,int YKub1,

int ZnachKub2,int XKub2,int YKub2,

int ZnachKub3,int XKub3,int YKub3,

int ZnachKub4,int XKub4,int YKub4

)

{

AnsiString strTmp=IntToStr(Type)+";"+IntToStr(MyCurOch)+";"+IntToStr(MyWholeOch)+";"+

IntToStr(ZnachKub1)+";"+IntToStr(XKub1)+";"+IntToStr(YKub1)+";"+

IntToStr(ZnachKub2)+";"+IntToStr(XKub2)+";"+IntToStr(YKub2)+";"+

IntToStr(ZnachKub3)+";"+IntToStr(XKub3)+";"+IntToStr(YKub3)+";"+

IntToStr(ZnachKub4)+";"+IntToStr(XKub4)+";"+IntToStr(YKub4)+";";

return strTmp.c_str();

}

//---------------------------------------------------------------------------

int* __fastcall TMainForm::CharToMas(char* charPriem)

{

AnsiString strPriem=charPriem;

MasPriem=new int[15];

int y=0;

int PrevDelim=0;

int CurDelim;

for(int i=1;i<=strPriem.Length();i++)

{

if(IsDelimiter(";",strPriem,i))

{

MasPriem[y++]=StrToInt(MidStr(strPriem,PrevDelim+1,i-PrevDelim-1));

PrevDelim=i;

}

}

return MasPriem;

}

//---------------------------------------------------------------------------

//--------------------------------------------------------------------------

void __fastcall TMainForm::btBrosit2Click(TObject *Sender)

{

Graphics::TBitmap *Bitmap1 = new Graphics::TBitmap();

char strSend[70];

AnsiString strCat;

if(IsServer)

{

NomHoda++;

strCat="";

}

else

{

strCat="_2";

}

if(KolKub==1)

{

int ZnachKub, XKub, YKub ;

randomize();

ZnachKub = random(6)+1;

XKub=random(126)+14;

YKub=random(126)+14;

Bitmap1->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(ZnachKub)+strCat);

Kubiki1[0]->Picture->Bitmap=Bitmap1;

Kubiki1[0]->Left=XKub;

Kubiki1[0]->Top=YKub;

Kubiki1[0]->Visible=true;

MyCurOch=ZnachKub;

MyWholeOch=MyWholeOch+MyCurOch;

strcpy(strSend,DannieToChar(1, MyCurOch, MyWholeOch, ZnachKub, XKub, YKub));

}

else if (KolKub==2)

{

int ZnachKub1, XKub1, YKub1, ZnachKub2, XKub2, YKub2;

randomize();

ZnachKub1 = random(6)+1;

XKub1=random(126)+14;

YKub1=random(52)+14;

Bitmap1->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(ZnachKub1)+strCat);

Kubiki1[0]->Picture->Bitmap=Bitmap1;

Kubiki1[0]->Left=XKub1;

Kubiki1[0]->Top=YKub1;

Kubiki1[0]->Visible=true;

ZnachKub2 = random(6)+1;

XKub2=random(126)+14;

YKub2=random(52)+88;

Bitmap1->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(ZnachKub2)+strCat);

Kubiki1[1]->Picture->Bitmap=Bitmap1;

Kubiki1[1]->Left=XKub2;

Kubiki1[1]->Top=YKub2;

Kubiki1[1]->Visible=true;

MyCurOch=ZnachKub1+ZnachKub2;

MyWholeOch=MyWholeOch+MyCurOch;

strcpy(strSend,DannieToChar(1, MyCurOch, MyWholeOch, ZnachKub1, XKub1, YKub1, ZnachKub2, XKub2, YKub2));

}

else if (KolKub==3)

{

int ZnachKub1, XKub1, YKub1, ZnachKub2, XKub2, YKub2, ZnachKub3, XKub3, YKub3;

randomize();

ZnachKub1 = random(6)+1;

XKub1=random(126)+14;

YKub1=random(27)+14;

Bitmap1->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(ZnachKub1)+strCat);

Kubiki1[0]->Picture->Bitmap=Bitmap1;

Kubiki1[0]->Left=XKub1;

Kubiki1[0]->Top=YKub1;

Kubiki1[0]->Visible=true;

ZnachKub2 = random(6)+1;

XKub2=random(126)+14;

YKub2=random(27)+63;

Bitmap1->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(ZnachKub2)+strCat);

Kubiki1[1]->Picture->Bitmap=Bitmap1;

Kubiki1[1]->Left=XKub2;

Kubiki1[1]->Top=YKub2;

Kubiki1[1]->Visible=true;

ZnachKub3 = random(6)+1;

XKub3=random(126)+14;

YKub3=random(28)+112;

Bitmap1->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(ZnachKub3)+strCat);

Kubiki1[2]->Picture->Bitmap=Bitmap1;

Kubiki1[2]->Left=XKub3;

Kubiki1[2]->Top=YKub3;

Kubiki1[2]->Visible=true;

MyCurOch=ZnachKub1+ZnachKub2+ZnachKub3;

MyWholeOch=MyWholeOch+MyCurOch;

strcpy(strSend,DannieToChar(1, MyCurOch, MyWholeOch, ZnachKub1, XKub1, YKub1, ZnachKub2, XKub2, YKub2, ZnachKub3, XKub3, YKub3));

}

else

{

int ZnachKub1, XKub1, YKub1, ZnachKub2, XKub2, YKub2, ZnachKub3, XKub3, YKub3, ZnachKub4, XKub4, YKub4;

randomize();

ZnachKub1 = random(6)+1;

XKub1=random(52)+14;

YKub1=random(52)+14;

Bitmap1->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(ZnachKub1)+strCat);

Kubiki1[0]->Picture->Bitmap=Bitmap1;

Kubiki1[0]->Left=XKub1;

Kubiki1[0]->Top=YKub1;

Kubiki1[0]->Visible=true;

ZnachKub2 = random(6)+1;

XKub2=random(52)+88;

YKub2=random(52)+14;

Bitmap1->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(ZnachKub2)+strCat);

Kubiki1[1]->Picture->Bitmap=Bitmap1;

Kubiki1[1]->Left=XKub2;

Kubiki1[1]->Top=YKub2;

Kubiki1[1]->Visible=true;

ZnachKub3 = random(6)+1;

XKub3=random(52)+14;

YKub3=random(52)+88;

Bitmap1->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(ZnachKub3)+strCat);

Kubiki1[2]->Picture->Bitmap=Bitmap1;

Kubiki1[2]->Left=XKub3;

Kubiki1[2]->Top=YKub3;

Kubiki1[2]->Visible=true;

ZnachKub4 = random(6)+1;

XKub4=random(52)+88;

YKub4=random(52)+88;

Bitmap1->LoadFromResourceName((unsigned int)HInstance,"KUB"+IntToStr(ZnachKub4)+strCat);

Kubiki1[3]->Picture->Bitmap=Bitmap1;

Kubiki1[3]->Left=XKub4;

Kubiki1[3]->Top=YKub4;

Kubiki1[3]->Visible=true;

MyCurOch=ZnachKub1+ZnachKub2+ZnachKub3+ZnachKub4;

MyWholeOch=MyWholeOch+MyCurOch;

strcpy(strSend,DannieToChar(1, MyCurOch, MyWholeOch, ZnachKub1, XKub1, YKub1, ZnachKub2, XKub2, YKub2,ZnachKub3, XKub3, YKub3, ZnachKub4, XKub4, YKub4));

}

switch(choosenProt)

{

case 0:

IPXSend(strSend);

break;

case 1:

TCPIPSend(AnsiString(strSend));

break;

case 2:

NetBiosSend(strSend);

break;

case 3:

MailSlotSend(strSend);

break;

case 4:

PipeSend(strSend);

break;

}

enum TypeDannihForTabl DannieForTabl;

DannieForTabl=yabrosil;

ZapolnTabl(DannieForTabl);

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;

}



?