-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.cpp
More file actions
137 lines (118 loc) · 3.85 KB
/
server.cpp
File metadata and controls
137 lines (118 loc) · 3.85 KB
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
#include "server.h"
#include <QDebug>
#include <QMessageBox>
#include <QDataStream>
// Testing changes
// More changes
// TESTING
QMap<QString, SGWidget*> server::_object_dictionary;
SGTCPSocket server::sg_socket;
const QString server::CREATE_ACCOUNT = "CACC";
const QString server::LOGIN = "LOGN";
const QString server::LOGOUT = "LOGT";
const QString server::RECOVER_USERNAME = "RUSR";
const QString server::RECOVER_PASSWORD = "RPWD";
const QString server::GROUP_CREATE = "CGRP";
const QString server::GROUP_JOIN = "JGRP";
const QString server::GROUP_LEAVE = "LGRP";
const QString server::CHAT_SEND = "GCHT";
const QString server::WHITEBOARD_DRAW = "WBLN";
const QString server::WHITEBOARD_UPDATE = "UPWB";
const QString server::WHITEBOARD_SAVE = "SVWB";
const QString server::FLASHCARD_SET_FRONT = "FCFT";
const QString server::FLASHCARD_SET_BACK = "FCBK";
const QString server::HOMEPAGE_UPDATE = "UPHP";
const QString server::HOMEPAGE_NEW_FAVORITE = "NWFG";
const QString server::HOMEPAGE_REMOVE_FAVORITE = "RMFG";
const QString server::SOCIAL_SEARCH_USER = "SUSR";
const QString server::SOCIAL_ADD_FRIEND = "ADFR";
const QString server::SOCIAL_REMOVE_FRIEND = "RMFR";
const QString server::SECURITY_QUESTIONS = "REQQ";
const QString server::SECURITY_SET_QUESTIONS = "SETQ";
const QString server::SECURITY_SET_ANSWERS = "SETA";
const QString server::CHECK_SECURITY_ANSWER = "CHKA";
const QString server::CHECK_SECURITY_CODE = "CHKC";
const QString server::UPDATE_PASSWORD = "CHPW";
server::server(QObject *parent) : QObject(parent)
{
//my_socket->connectToHost("18.221.67.202", 9001); // CSCI 150 SERVER
//my_socket->connectToHost("localhost", 24680);
//my_socket->connectToHost("52.53.198.189", 24680); // David's AWS server
}
/***
* Public
* Functions
* API
*/
void server::initialize()
{
sg_socket.connect_server();
connect(&sg_socket, &SGTCPSocket::new_message, incoming_message);
}
void server::clear_memory()
{
}
void server::add(QString key, SGWidget *value)
{
server::_object_dictionary.insert(key, value);
qDebug() << "Server: added (" << key << "," << value << ")";
}
void server::remove(QString class_key)
{
server::_object_dictionary.remove(class_key);
}
void server::remove(SGWidget *object_pointer)
{
QMap<QString, SGWidget*>::iterator i = _object_dictionary.begin();
while (i != _object_dictionary.end()) {
if (i.value() == object_pointer)
i = _object_dictionary.erase(i);
else
++i;
}
}
void server::send(const QString &outgoing_message)
{
//qDebug() << "server sending" << outgoing_message;
sg_socket.write(outgoing_message);
}
void server::send(const QByteArray &outgoing_message)
{
sg_socket.write(outgoing_message);
}
void server::send(const char *outgoing_message)
{
qDebug() << "server sending" << outgoing_message;
sg_socket.write(QString(outgoing_message));
}
bool server::request_response(QString outgoing_message, QString &response)
{
sg_socket.write(outgoing_message);
return sg_socket.read_socket_helper(response);
}
void server::test(QString key, QString test_message)
{
//_object_dictionary[key]->enqueue(test_message);
}
/***
* SLOTS
*/
void server::incoming_message(QString& object_name, QByteArray& work_message)
{
qDebug() << "Object name:" << object_name;
qDebug() << "Message:" << work_message;
qDebug() << "\n";
if (_object_dictionary.contains(object_name) && (_object_dictionary[object_name] != nullptr))
{
_object_dictionary[object_name]->enqueue(work_message);
}
}
void server::setTimestamps(char arg)
{
if(arg == server::timestamp_local) {
timestamps.setTimeSpec(Qt::LocalTime);
}
else if(arg == server::timestamp_utc) {
timestamps.setTimeSpec(Qt::UTC);
}
}