-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspeak_parser.cpp
More file actions
45 lines (39 loc) · 1.28 KB
/
speak_parser.cpp
File metadata and controls
45 lines (39 loc) · 1.28 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
#include "speak_parser.h"
#include "game_server.h"
#include <iostream>
#include "common.h"
#include "database.h"
using namespace std;
bool SpeechParser::handlespeechInput(Player *p, string command)
{
// /msg Player "message" sends a message to player if theyre online
// /me "messeage" broadcasts to all online players your message
//REGEX PATTERNS
string input = command;
regex msgPattern("/msg (.+) (\"([^\"]*)\")");
smatch m;
if(input == "help")
{
//Help
server->printToUser(p, "Available Speech Commands: \n");
server->printToUser(p, "To message another player online in the server - /msg <player> \"Message\"");
return false;
}
if(regex_match(command, m, msgPattern))
{
if(db->findPlayerByName(m[1]) != NULL)
{
server->printToUser(db->findPlayerByName(m[1]), string(p->getUsername() + " Says: \n"));
string temp(m[3]);
temp += "\n";
server->printToUser(db->findPlayerByName(m[1]), temp);
return true;
}
else
{
server->printToUser(p, "The player you are looking for is either offline or doesnt exist");
return true;
}
}
return false;
}