Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:
//” ©«: Client.cpp
//Љ« бб "Љ«ЁҐв". ђҐ «Ё§ жЁп.
//Ђўв®а: ‘ҐаЈҐҐў Њ.‚. Ја.3352
//„ в : 21.05.06, ђҐ¤ ЄжЁп: 1.0
#include<iostream.h>
#include<conio.h>
#include "Client.h"
#include "Message.cpp"
#include "Server.cpp"
using namespace std;
////////////////////////////////////////////////////////////////
/*
try to register on server
0-all right
1-bad
*/
int CClient::regOnSrv(CServer*s)
{
//cout<<"\nClient#"<<id<<" tries to reg on server #" << s->getID() << "...";
int res = s->regCl(this);
if(res == 0 )
{
cout<<"\nClient(id "<<id<<") § ॣЁбваЁа®ў Server(id "<<s->getID()<<")";
return 0;
}
cout<<"\nClient(id "<<id<<") Ґ ᬮЈ § ॣЁбваЁа®ў вмбп Server(id "<<s->getID()
<<") ЋиЁЎЄ ь"<<res;
return 1;
};
////////////////////////////////////////////////////////////////
/*
read message
0-read ok
1-bad
*/
int CClient::readMsg(CMsg*m)
{
cout <<"\nClient(id "<<id<<") Ї®«гзЁ« ";
m->show();
if(m->getTo() == this->id){
//message ok, executing command
int mes = m->getCommand();
cout <<" Љ®¬¬ ¤ : ‘¤ўЁгвмбп :"<<mes;
return 0;
}
cout <<"‘®®ЎйҐЁҐ Ґ ¬®Ґ";
return 1;
};
////////////////////////////////////////////////////////////////
int CClient::readMsgRet(CMsg*m)
{
return m->getCommand();
}
////////////////////////////////////////////////////////////////
/*
send msg to client #toID
*/
int CClient::sendMsg(int comm,CServer*s,int toID)
{
CMsg* m = new CMsg(this->getID(),toID,comm);
cout <<"\nClient(id "<<this->getID()<<") ®вЇа ўЁ« ";
m->show();
int res = s->resend(m);
if(res==0)
cout <<"\nClient(id "<<this->getID()<<") ‘®®ЎйҐЁҐ ¤®бв ў«Ґ®";
else
cout <<"\nClient(id "<<this->getID()<<") ‘ҐаўҐа ўҐаг«:"<<res;
return res;
};
////////////////////////////////////////////////////////////////
/*
send msg to all client througth server
*/
int CClient::sendMsgAll(int comm,CServer*s)
{
cout <<"\nClient(id "<<this->getID()<<"): ®вбл« Ґв ўбҐ¬ Є«ЁҐв ¬ Є®¬ ¤г:"<<comm;
int res = s->resendAll(this, comm);
if(res==0)
cout<<"\nClient(id "<<this->getID()<<"): ўбҐ б®®ЎйҐЁп ¤®бв ў«Ґл";
else
cout<<"\nClient(id "<<this->getID()<<"): ‘ҐаўҐа ўҐаг«:"<<res;
return res;
}
////////////////////////////////////////////////////////////////
/*
Constructor
*/
CClient::CClient():id(nextID++)
{
count++;
cout <<"\n>Client(id "<<id<<")\n";
};
////////////////////////////////////////////////////////////////
/*
Destructor
*/
CClient::~CClient()
{
count--;
cout <<"\n>~Client(id "<<id<<")";
};
////////////////////////////////////////////////////////////////
/*
show info about client
*/
void CClient::show()const
{
cout<<"Client(id "<<id<<")";
}
////////////////////////////////////////////////////////////////
/*
Show info: how many clients avaliable
*/
void CClient::showCInfo()const
{
cout << "\nЉ®«ЁзҐбвў® Є«ЁҐв®ў:" << count <<".";
}
////////////////////////////////////////////////////////////////
/*
getter for id
*/
int CClient::getID()const
{
return id;
}
Соседние файлы в папке Kurs