
Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа 4 / l4bis / SERVER
.CPP#ifndef CPP006
#define CPP006
#include "server.h"
Server::Server()
{
};
int Server::DupClient(char Name[30])
{
ClientList.tobegin();
if (!ClientList.Empty())
{
char S[30];
while (!ClientList.TheEnd())
{
((ClientList.GetDate()).GetCl()).GetName(S);
if (strcmp(Name,S) == 0)
return 1;
ClientList.move();
};
((ClientList.GetDate()).GetCl()).GetName(S);
if (strcmp(Name,S) == 0)
return 1;
};
return 0;
}
void Server::addClient(char Name[30])
{
if (DupClient(Name))
cout<<"Server : Client "<<Name<<" is already in list."<<endl;
else
{
Client Cl(Name);
Sdate C;
C.SetCl(Cl);
C.SetNReq(0);
ClientList.add(C);
cout<<"Server : Client "<<Name<<" added."<<endl;
};
};
void Server::add(Sdate C)
{
ClientList.add(C);
}
void Server::delClient(char Name[30])
{
if (DupClient(Name))
{
ClientList.del();
cout<<"Server : Client "<<Name<<" deleted."<<endl;
}
};
void Server::personalmsg(char Name[30],char Text[100])
{
if (DupClient(Name))
{
Sdate C;
C = (ClientList.GetCur());
Client Cl;
Cl = C.GetCl();
Cl.getmsg(Text);
C.SetNReq(C.GetNReq() + 1);
C.SetCl(Cl);
add(C);
}
};
void Server::broadcastmsg(char Text[100])
{
Sdate ND;
Client Cl;
linlist<Sdate> NS;
while (!ClientList.Empty())
{
ClientList.tobegin();
ND = ClientList.GetCur();
Cl = ND.GetCl();
Cl.getmsg(Text);
ND.SetNReq(ND.GetNReq() + 1);
ND.SetCl(Cl);
NS.add(ND);
};
ClientList.Set(NS);
};
void Server::requestcheck()
{
char S[30];
Sdate ND;
Client Cl;
linlist<Sdate> NS;
while (!ClientList.Empty())
{
ClientList.tobegin();
ND = ClientList.GetCur();
Cl = ND.GetCl();
while (Cl.sendrequest())
{
Cl.GetName(S);
cout<<"Client "<<S<<" message delivered"<<endl;
ND.SetNReq(ND.GetNReq()-1);
};
ND.SetCl(Cl);
NS.add(ND);
};
ClientList.Set(NS);
};
void Server::workaccount()
{
cout<<endl<<"Server working account:"<<endl;
if (!ClientList.Empty())
{
ClientList.tobegin();
char S[30];
int UnDel,UnRep;
while (!ClientList.TheEnd())
{
((ClientList.GetDate()).GetCl()).GetName(S);
UnRep = ((ClientList.GetDate()).GetCl()).getreq();
UnDel = (ClientList.GetDate()).GetNReq();
if (UnRep != 0)
cout <<"Client "<<S<<" : "<<UnRep<<" messages are without request"<<endl;
if (UnDel != 0)
cout <<"Client "<<S<<" : "<<UnDel<<" messages are not yet delivered"<<endl;
if (UnDel > UnRep)
cout <<"Client "<<S<<" : "<<(UnDel-UnRep)<<" messages are lost!"<<endl;
if ((UnDel == 0)&&(UnRep == 0))
cout <<"Client "<<S<<" : "<<"all is OK"<<endl;
ClientList.move();
}
((ClientList.GetDate()).GetCl()).GetName(S);
UnRep = ((ClientList.GetDate()).GetCl()).getreq();
UnDel = (ClientList.GetDate()).GetNReq();
if (UnRep != 0)
cout <<"Client "<<S<<" : "<<UnRep<<" messages are without request"<<endl;
if (UnDel != 0)
cout <<"Client "<<S<<" : "<<UnDel<<" messages are not yet delivered"<<endl;
if (UnDel > UnRep)
cout <<"Client "<<S<<" : "<<(UnDel-UnRep)<<" messages are lost!"<<endl;
if ((UnDel == 0)&&(UnRep == 0))
cout <<"Client "<<S<<" : "<<"all is OK"<<endl<<endl;
getch();
}
}
Server::~Server()
{}
#endif
Соседние файлы в папке l4bis