Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа #4 / LAB_4 / Server
.cpp//” ©«: Server.cpp
//Љ« бб "‘ҐаўҐа". ђҐ «Ё§ жЁп.
//Ђўв®а: ‘ҐаЈҐҐў Њ.‚. Ја.3352
//„ в : 21.05.06, ђҐ¤ ЄжЁп: 1.0
#include<iostream.h>
#include<conio.h>
#include "Server.h"
////////////////////////////////////////////////////////////////
/*
register client on server
0-registered
1-bad
*/
int CServer::regCl(CClient*c)
{
if(c==NULL)
{
cout<<"\nServer: ЌҐ ўҐа п ббл«Є Є«ЁҐв";
return 1;
}
cout << "\nServer: Client(id "<<c->getID()<<")";
CClient* cl = clients->getClientByID(c->getID());
if(cl != NULL)
{
cout<<" “¦Ґ Ўл« § ॣЁбваЁа®ў ";
return 1;
}
clients->insertItem(c);
cout <<" “бЇҐи® § ॣЁбваЁа®ў ";
return 0;
};
////////////////////////////////////////////////////////////////
/*
send msg to reciver
0 - client read msg
1 - client not read msg
2 - client(reciver) not registred
3 - client(sender) not registred
*/
int CServer::resend(CMsg* m)
{
cout<<"\nServer: ЇаҐб« « ";
m->show();
CClient* c = clients->getClientByID(m->getFrom());
if(c == NULL)
{
cout <<"\nServer: Client(id "<<m->getFrom()<<")- Ґ § ॣЁбваЁа®ў (®вЇа ўЁвҐ«м)";
return 3;
}
c = clients->getClientByID(m->getTo());
if(c == NULL)
{
cout <<"\nServer: Client(id "<<m->getTo()<<") - Ґ § ॣЁбваЁа®ў (Ї®«гз ⥫м)";
return 2;
}
int res = c->readMsg(m);
if(res == 0 )
{
cout <<"\nServer: Client(id "<<m->getTo()<<") Їа®зҐ« б®®ЎйҐЁҐ";
m->show();
return 0;
}
cout <<"\nServer: Client(id "<<m->getTo()<<") Ґ Їа®зҐ« б®®ЎйҐЁҐ";
m->show();
return 1;
}
////////////////////////////////////////////////////////////////
/*
send msg to all clients
-1 - not registred
0 -ok
>0 - how many not got message
*/
int CServer::resendAll(CClient* from, int comm)
{
cout<<"\n\nServer: Ћвбл« Ґвбп б®®ЎйҐЁҐ б Є®¬ ¤®© "<<comm;
cout<<" ўбҐ¬ Є«ЁҐв ¬ ®в \n Client(id "<< from->getID()<<")";
CClient* c = clients->getClientByID(from->getID());
if(c == NULL)
{
cout <<"\nSServer: Client(id "<<from->getID()<<")- Ґ § ॣЁбваЁа®ў (®вЇа ўЁвҐ«м)";
return -1;
}
clients->resetNextClient();
int res = 0, numCl = 0;
do{
CClient* c = clients->getCurClient();
CMsg* m = new CMsg(from->getID(),c->getID(),comm);
res += c->readMsg(m);
numCl++;
}while(clients->hasNextClient());
cout<<"\nServer: Ї®б« « б®®ЎйҐЁҐ "<<numCl<<" Є«ЁҐв ¬. €§ Ёе Ґ Ї®«гзЁ«Ё ҐЈ® "<<res;
return res;
}
////////////////////////////////////////////////////////////////
/*
Constructor
*/
CServer::CServer():id(nextID++)
{
count++;
clients = new CSrvList();
cout<<"\n>Server";
};
////////////////////////////////////////////////////////////////
/*
Destructor
*/
CServer::~CServer()
{
count--;
clients->clear();
cout<<"\n>~Server";
};
////////////////////////////////////////////////////////////////
/*
show info
*/
void CServer::show()const
{
cout<<"\n‡ ॣЁбваЁа®ў лҐ Є«ЁҐвл:";
clients->show();
}
////////////////////////////////////////////////////////////////
/*
get server id
*/
int CServer::getID()const
{
return id;
}
Соседние файлы в папке LAB_4