Скачиваний:
32
Добавлен:
01.05.2014
Размер:
3.15 Кб
Скачать
//” ©«: 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