Exemplo n.º 1
0
 public function HandleRemoteProcedureCall($func, $username, $pw, $plantname, $code, $plantid)
 {
     $plant = null;
     if ($this->m_User == null) {
         $this->m_User = $this->m_Database->GetUser($username);
     }
     if ($this->m_User != null) {
         if ($plantid != null) {
             $plant = $this->m_User->GetPlantById($plantid);
         } else {
             $plant = $this->m_User->GetPlant($plantname);
         }
     }
     $res = "";
     switch ($func) {
         case "IsLoggedIn":
             $res = $this->m_Server->IsLoggedIn();
             break;
         case "Auth":
             $res = $this->m_Server->LogIn($username, $pw);
             break;
         case "Logout":
             $res = $this->m_Server->LogOut();
             break;
         case "Register":
             $res = $this->m_Server->Register($username, $pw);
             break;
         case "SavePlant":
             if ($plant != null) {
                 $res = $plant->Save($code);
             } else {
                 $res = $this->CreatePlant($plantname, $code);
             }
             break;
         case "CreatePlant":
             $res = $this->CreatePlant($plantname, $code);
             break;
         case "ActivatePlant":
             $res = $plant->Activate();
             break;
         case "GetPlantList":
             if (isset($this->m_User)) {
                 $res = $this->m_User->GetPlantList();
             } else {
                 $res = "{ success: false, msg: 'Sie sind nicht angemeldet' }";
             }
             break;
         case "GetSeasonList":
             $res = $this->GetSeasonScoreList();
             break;
         case "DeletePlant":
             if ($plant != null) {
                 $res = $plant->Delete();
             } else {
                 $res = "{ success: false, msg: \"Keine Pflanze mit dem Namen '" . $plantname . "' für den Nutzer '" . $username . "' gefunden.\" }";
             }
             break;
         case "TestPlant":
             break;
         case "CheckSyntax":
             # Create a temporary plant
             $plant = new Plant(0, 0, $plantname, $code, 0, 0);
             $res = $plant->Validate();
             break;
         default:
             $res = "{ success : false, msg: \"Unkown RPC call '" . $func . "'\"}";
     }
     return new RPCAnswer($func, $res);
 }