-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.cpp
151 lines (132 loc) · 3.08 KB
/
user.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "user.h"
#include "Parsing.h"
#include <string>
#include <iostream>
int cs457::user::closeSocket()
{
int retint = -100;
if (cs457::user::userSocket)
{
retint = userSocket->closeSocket();
socketActive = false;
}
return retint;
}
void cs457::user::setSocket(shared_ptr<cs457::tcpUserSocket> inputSocket)
{
socketActive = true;
userSocket = inputSocket;
}
//c++ is weird, watch the defaults here.
cs457::user::user(std::string uname, std::string pword /*= "@"*/,
std::string lvl /*= "user"*/, std::string banStatus, shared_ptr<cs457::tcpUserSocket> inputSocket /*= nullptr*/)
{
username = uname;
password = pword;
level = lvl;
if (inputSocket)
{
userSocket = inputSocket;
socketActive = true;
}
else
{
userSocket = nullptr;
socketActive = false;
}
if (banStatus == "true")
banned = true;
else
banned = false;
}
//This is the one I'm using right now for adding as the connect.
cs457::user::user(shared_ptr<cs457::tcpUserSocket> inputSocket)
{
userSocket = inputSocket;
socketActive = true;
std::string msg; int val;
//recieve the first command from the client to attempt to build a new user.
tie(msg, val) = userSocket.get()->recvString();
if(val > 0){
//append the crlf thing???
//ohh yeah probably do this clientside!!!!TODO
Parsing::IRC_message message(msg);
if(message.command == "PASS"){
//New user registering on first connection.
username = message.name;
//set the new hypothetical users password
password = message.params[0];
}
else
{
//no password given.
username = message.name;
}
}
else{
/*Something went wrong!!!*/
}
realName = "";
awayMessage = "I, " + username + " am not here right now.";
}
std::string cs457::user::getName()const
{
return username;
}
void cs457::user::setName(std::string name)
{
username = name;
}
void cs457::user::setAwayMessage(std::string newMessage)
{
awayMessage = newMessage;
return;
}
std::string cs457::user::toString()
{
//helpful for the file writing.
std::string ban;
if(banned)
ban = "true";
else
ban = "false";
std::string retStr = username + " " + password + " " + level + " " + ban;
return retStr;
}
std::string cs457::user::getAwayMessage(){
return awayMessage;
}
void cs457::user::setLevel(std::string newLevel)
{
level = newLevel;
}
std::string cs457::user::getLevel()
{
return level;
}
std::string cs457::user::getPassword()
{
return password;
}
bool cs457::user::checkPassword(std::string match)
{
return password == match;
}
void cs457::user::setPassword(std::string pass)
{
password = pass;
}
void cs457::user::setRealName(std::string name)
{
realName = name;
}
std::string cs457::user::getRealName()
{
return realName;
}
/*
std::ostream& operator<<(std::ostream& os, const cs457::user us)
{
os << us.getName();
return os;
}*/