summaryrefslogtreecommitdiff
path: root/vfg/src/Asterisk.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'vfg/src/Asterisk.cpp')
-rwxr-xr-xvfg/src/Asterisk.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/vfg/src/Asterisk.cpp b/vfg/src/Asterisk.cpp
index 5392ade..ae85269 100755
--- a/vfg/src/Asterisk.cpp
+++ b/vfg/src/Asterisk.cpp
@@ -2,6 +2,7 @@
//there is no notification that there is someone in the queue
+//but there is a status message you can check periodically...
Asterisk::Asterisk()
{
@@ -10,13 +11,25 @@ Asterisk::Asterisk()
udpConnection.SetNonBlocking(true);
cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"database put GAME passcode 1234\"'");
state=WAITING;
+ printf("Asterisk: created socket and connected to server\n");
}
void Asterisk::startGame(){
- //if (state=IDLE) {
+ if (state!=PLAYING) {
cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"devstate change Custom:GAME NOT_INUSE\"'");
+ printf("Asterisk: attempting to dequeue\n");
state=STARTING;
- //}
+ }
+}
+void Asterisk::endGame(string score){
+ if (state==PLAYING) {
+ cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"database put GAME statuscode "+score+"\"'");
+ string emsg="ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"hangup request "+playerCode+"\"'";
+ printf("%s\n",emsg.c_str());
+ cmd(emsg);
+ printf("Asterisk: hanging up %s\n",playerCode.c_str());
+ state=WAITING;
+ }
}
void Asterisk::cmd(string s) {
file = popen(s.c_str(), "r");
@@ -26,6 +39,7 @@ void Asterisk::cmd(string s) {
}
int Asterisk::update(){
+ //how to capture stdin response from popen
/*
if (state==WAITING||state==STARTING) {
char buf[100];
@@ -47,16 +61,18 @@ int Asterisk::update(){
udpConnection.Receive(udpMessage,10000);
string msg=udpMessage;
if(msg!=""){
+ printf("Asterisk: %s\n",msg.c_str());
if (msg.length()>3) {
//printf("status msg: %s\n",msg.c_str());
if (msg.substr(0,5)=="Local") {
state=PLAYING;
+ playerCode=msg.substr(0,msg.length()-1);
+ printf("Asterisk: game started: code %s\n",playerCode.c_str());
return 1000;
}
return 0;
}
else {
- //printf("cmd: %s\n",msg.c_str());
return ofToInt(msg);
}
}