-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
executable file
·94 lines (91 loc) · 2.03 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include<iostream>
#include<server.h>
#include<client.h>
#include<msgServer.h>
#include<encodedServer.h>
using namespace std;
int main()
{
client *client1 = new client();
int idno;
cout<<"enter client id number:";
cin>>idno;
client *client2 = new client(idno);
server *mServer = new msgServer();
server *encodServer = new encodedServer();
mServer->establishConnection(client1, client2);
encodServer->establishConnection(client1, client2);
char c1op;
cout<<"Client "<< client1->GetID()<<", make a connection?(y/n)";
cin>>c1op;
char c2op;
cout<<"Client "<< client2->GetID()<<", make a connection?(y/n)";
cin>>c2op;
if(c1op=='n'||c2op=='n')
{
cout<<"No connection made\n"; //file
return 0;
}
char econ;
cout<<"Encrypted Connection?(y/n)";
cin>>econ;
char op1, op2;
if(econ=='y')
{
cout<<"Client "<<client1->GetID()<<", does client "<<client2->GetID()<<" get the key?(y/n)";
cin>>op1;
if(op1=='y')
client2->SetPossesKey(true);
cout<<"Client "<<client2->GetID()<<", does client "<<client1->GetID()<<" get the key?(y/n)";
cin>>op2;
if(op2=='y')
client1->SetPossesKey(true);
}
string carr;
bool switchc = true;
cin.ignore();
bool toggle = true;
do{
if(switchc)
{
cout<<"Client "<<client1->GetID()<<":";
switchc = false;
}else{
cout<<"Client "<<client2->GetID()<<":";
switchc = true;
}
getline(cin, carr);
if(econ=='y')
{
if(toggle)
{
toggle = false;
if(op1=='n'){
encodServer->swapClients();
mServer->swapClients();
encodServer->sendMessage(carr);
}else{
encodServer->swapClients();
mServer->swapClients();
mServer->sendMessage(carr);
}
}else{
toggle = true;
if(op2=='n'){
encodServer->swapClients();
mServer->swapClients();
encodServer->sendMessage(carr);
}else{
encodServer->swapClients();
mServer->swapClients();
mServer->sendMessage(carr);
}
}
}else{
encodServer->swapClients();
mServer->swapClients();
mServer->sendMessage(carr);
}
}while(!carr.empty());
return 0;
}