Skip to content

Commit 80f5c0a

Browse files
committed
Update
1 parent 8b0869b commit 80f5c0a

File tree

2 files changed

+73
-59
lines changed

2 files changed

+73
-59
lines changed

client.cpp

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -142,20 +142,25 @@ class client {
142142

143143
void reg() {
144144
char buffer[1024];
145+
bool ok;
145146
do {
146147
clear();
147148
printw("Sign Up\nEnter Username: ");
148149
getstr(buffer);
149150
sock.send(buffer);
150-
} while (sock.recv() != "ok");
151+
if ((ok = sock.recv() != "ok"))
152+
ui.notification("Kurwa", {"This username is already in use."});
153+
} while (ok);
151154
printw("Enter Password: ");
152155
getstr(buffer);
153156
sock.send(buffer);
154157
clear();
158+
ui.notification("Success!", {"You have registered a new account."});
155159
}
156160

157161
void log() {
158162
char buffer[1024];
163+
bool ok;
159164
do {
160165
printw("Sign In\nEnter Username: ");
161166
getstr(buffer);
@@ -164,7 +169,11 @@ class client {
164169
getstr(buffer);
165170
sock.send(buffer);
166171
clear();
167-
} while (sock.recv() != "ok");
172+
if ((ok = sock.recv() != "ok"))
173+
ui.notification("Kurwa",
174+
{"The password or username is incorrect."});
175+
} while (ok);
176+
ui.notification("Success!", {"You signed in to your account."});
168177
}
169178
client(SSL* ssl, clsUi& ui) : sock(ssl), ui(ui) {}
170179
};
@@ -209,8 +218,7 @@ class project {
209218
owner.sock.send("removeDir " + path + it.key());
210219
owner.sock.send("createFile " + path + it.key());
211220
if (owner.sock.recv() == "ok")
212-
owner.sock.sendFile(prjPath + path + it.key(),
213-
&progressBar);
221+
owner.sock.sendFile(prjPath + path + it.key());
214222
} else if (newjs[it.key()].is_object()) {
215223
compJson(it.value(), newjs[it.key()],
216224
path + it.key() + '/');
@@ -219,8 +227,7 @@ class project {
219227
it.key().c_str());
220228
owner.sock.send("createFile " + path + it.key());
221229
if (owner.sock.recv() == "ok")
222-
owner.sock.sendFile(prjPath + path + it.key(),
223-
&progressBar);
230+
owner.sock.sendFile(prjPath + path + it.key());
224231
}
225232
} else {
226233
if (it.value().is_object() || it.value().is_null()) {
@@ -247,8 +254,7 @@ class project {
247254
it.key().c_str());
248255
owner.sock.send("createFile " + path + it.key());
249256
if (owner.sock.recv() == "ok")
250-
owner.sock.sendFile(prjPath + path + it.key(),
251-
&progressBar);
257+
owner.sock.sendFile(prjPath + path + it.key());
252258
}
253259
}
254260
}
@@ -261,19 +267,24 @@ class project {
261267

262268
void set() {
263269
char buffer[1024];
264-
/* do {
270+
bool ok;
271+
do {
265272
printw("Path to your project: ");
266273
getstr(buffer);
267274
prjPath = buffer;
268-
} while (!fs::exists(prjPath) && !fs::is_directory(prjPath)); */
269-
prjPath = "/home/jomm/Documents/kurwa/client/test/";
270-
// prjPath += '/';
275+
if ((ok = !fs::exists(prjPath) && !fs::is_directory(prjPath)))
276+
owner.ui.notification("kurwa", {"Path is invalid."});
277+
} while (ok);
278+
prjPath += '/';
279+
// prjPath = "/home/jomm/Documents/kurwa/client/test/";
271280
do {
272281
printw("Name of your project: ");
273282
getstr(buffer);
274283
prjName = buffer;
275284
owner.sock.send(prjName);
276-
} while (owner.sock.recv() != "ok");
285+
if ((ok = owner.sock.recv() != "ok"))
286+
owner.ui.notification("Kurwa", {"Project name is invalid."});
287+
} while (ok);
277288
clear();
278289
}
279290
void open() {
@@ -287,11 +298,12 @@ class project {
287298
json check = genJson(prjPath);
288299
compJson(curr, check, "");
289300
owner.sock.send(check.dump());
290-
} else if (!strcmp(buffer, "quit")) {
291-
owner.sock.send("quit");
301+
} else if (!strcmp(buffer, "back")) {
302+
owner.sock.send("back");
292303
break;
293304
}
294305
}
306+
clear();
295307
}
296308
void download() {
297309
string command;
@@ -303,7 +315,7 @@ class project {
303315
fs::create_directory(prjPath + path);
304316
} else if (action == "createFile") {
305317
printw("File %s was created\n", path.c_str());
306-
owner.sock.recvFile(prjPath + path, &progressBar);
318+
owner.sock.recvFile(prjPath + path);
307319
}
308320
}
309321
}
@@ -338,29 +350,33 @@ int main(int argc, char* argv[]) {
338350
client.log();
339351
break;
340352
}
341-
project project(client);
342-
switch (ui.menu("Choose one option:",
343-
{"Create new project", "Open existing project",
344-
"Download project from server"})) {
345-
case 0:
346-
client.sock.send("createPrj");
347-
project.set();
348-
project.open();
349-
break;
350-
case 1:
351-
client.sock.send("openPrj");
352-
project.set();
353-
project.open();
354-
break;
355-
case 2:
356-
client.sock.send("downloadPrj");
357-
project.set();
358-
project.download();
359-
project.open();
360-
break;
353+
while (true) {
354+
project project(client);
355+
switch (ui.menu("Choose one option:",
356+
{"Create new project", "Open existing project",
357+
"Download project from server", "Exit"})) {
358+
case 0:
359+
client.sock.send("createPrj");
360+
project.set();
361+
project.open();
362+
break;
363+
case 1:
364+
client.sock.send("openPrj");
365+
project.set();
366+
project.open();
367+
break;
368+
case 2:
369+
client.sock.send("downloadPrj");
370+
project.set();
371+
project.download();
372+
project.open();
373+
break;
374+
case 3:
375+
client.sock.send("quit");
376+
endwin();
377+
SSL_CTX_free(ctx);
378+
client.sock.close();
379+
return 0;
380+
}
361381
}
362-
endwin();
363-
364-
SSL_CTX_free(ctx);
365-
client.sock.close();
366382
}

server.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ class project {
179179
char uuidStr[37];
180180
uuid_unparse(uuid, uuidStr);
181181
prjPath = prjPath + uuidStr + '/';
182-
cout << prjPath << endl;
183182
fs::create_directory(prjPath);
184183
db.exec(
185184
"insert into projects (ownerId, prjName, dir, dirTree) "
@@ -203,7 +202,6 @@ class project {
203202
"isis", owner.id, owner.sock.recv().c_str(), &prjId,
204203
&uuid)) {
205204
prjPath = prjPath + uuid + '/';
206-
cout << prjPath << endl;
207205
owner.sock.send("ok");
208206
} else
209207
owner.sock.send("not ok");
@@ -212,12 +210,11 @@ class project {
212210

213211
void open(db& db) {
214212
string command;
215-
while ((command = owner.sock.recv()) != "quit") {
213+
while ((command = owner.sock.recv()) != "back") {
216214
if (command == "push") {
217215
string dirTree;
218216
db.exec("select dirTree from projects where id = ?;", "si",
219217
prjId, &dirTree);
220-
cout << dirTree << endl;
221218
owner.sock.send(dirTree);
222219
while ((command = owner.sock.recv())[0] != '{') {
223220
string action = command.substr(0, command.find(' '));
@@ -226,14 +223,14 @@ class project {
226223
if (path.find("../") != string::npos)
227224
owner.sock.send("not ok");
228225
else {
229-
owner.sock.send("ok");
230226
if (action == "createDir")
231227
fs::create_directory(path);
232228
else if (action == "removeDir")
233229
fs::remove_all(path);
234-
else if (action == "createFile")
230+
else if (action == "createFile") {
231+
owner.sock.send("ok");
235232
owner.sock.recvFile(path);
236-
else if (action == "removeFile")
233+
} else if (action == "removeFile")
237234
fs::remove(path);
238235
}
239236
}
@@ -259,18 +256,19 @@ void handleClient(client client, db& db, const string& path) {
259256
client.log(db);
260257
} else if (command == "signIn")
261258
client.log(db);
262-
project project(client, path);
263-
command = client.sock.recv();
264-
if (command == "createPrj") {
265-
project.create(db);
266-
project.open(db);
267-
} else if (command == "openPrj") {
268-
project.set(db);
269-
project.open(db);
270-
} else if (command == "downloadPrj") {
271-
project.set(db);
272-
project.download();
273-
project.open(db);
259+
while ((command = client.sock.recv()) != "quit") {
260+
project project(client, path);
261+
if (command == "createPrj") {
262+
project.create(db);
263+
project.open(db);
264+
} else if (command == "openPrj") {
265+
project.set(db);
266+
project.open(db);
267+
} else if (command == "downloadPrj") {
268+
project.set(db);
269+
project.download();
270+
project.open(db);
271+
}
274272
}
275273
client.sock.close();
276274
cout << "[-] Client disconnected." << endl;

0 commit comments

Comments
 (0)