示例#1
0
 public function showPage()
 {
     if (isset($_POST["login-username"]) && isset($_POST["login-password"])) {
         if (Users::checkLogin($_POST["login-username"], $_POST["login-password"])) {
             SessionStore::createSession($_POST["login-username"]);
             (new index())->showPage("You are now logged in.");
         } else {
             echo $this->getTemplateEngine()->render($this->getTemplateSnip("page"), ["title" => "Login", "content" => $this->getTemplateEngine()->render($this->getTemplate(), ["error" => "Your username or password appear incorrect."])]);
         }
     } else {
         echo $this->getTemplateEngine()->render($this->getTemplateSnip("page"), ["title" => "Login", "content" => $this->getTemplateEngine()->render($this->getTemplate(), [])]);
     }
 }
示例#2
0
 public function handleMessage($msg)
 {
     Logger::debug("IRC message received: {$msg}");
     $msg = explode(" ", $msg);
     switch ($msg[0]) {
         case "PASS":
             $this->password = trim($msg[1]);
             break;
         case "NICK":
             foreach ($this->server->getClients() as $client) {
                 if (strtolower($client->getNick()) === $msg[1]) {
                     $this->sendNumerical("NOTICE AUTH :*** That nick is already in use..");
                     break;
                 }
             }
             $this->setNick($msg[1]);
             break;
         case "USER":
             if ($this->password) {
                 if (Users::checkLogin($msg[1], $this->password)) {
                     $this->setIdent($msg[1]);
                     $this->setRealName($msg[4]);
                     $this->sendNumerical("001 {$this->nick} :Welcome to the Internet Relay Network {$this}");
                     $this->sendNumerical("002 {$this->nick} :Your host is shogchat, running version a development build.");
                     $this->sendNumerical("003 {$this->nick} :This server was created " . @date('r'));
                     $this->sendNumerical("375 {$this->nick} :=== Welcome to ShogChat IRC Bridge ====");
                     $this->sendNumerical("372 {$this->nick} :You are connected to the IRC bridge as {$this->nick}. All of your GitHub repos have a channel, just join the channel with the name of your repo and start chatting. If you get an error saying the channel doesn't exist, you might need to reload your repos on our website.");
                     $this->sendNumerical("372 {$this->nick} :-----------------------------");
                     $this->sendNumerical("372 {$this->nick} :(ShogChat)->shogAllTheChats()");
                     $this->sendNumerical("376 {$this->nick} :End of MOTD");
                     $this->sendNumerical("NICK " . $this->nick);
                     $this->authenticated = true;
                     $this->user = Users::getUser($msg[1]);
                 } else {
                     $this->sendNumerical("464 {$this->nick} :The password you have set is incorrect.");
                     $this->close();
                 }
             } else {
                 $this->sendNumerical("464 {$this->nick} :You haven't set a password.");
                 $this->close();
             }
             break;
         case "JOIN":
             if ($this->isAuthenticated()) {
                 $chans = explode(",", $msg[1]);
                 foreach ($chans as $chan) {
                     $chan = Channels::getChannel(trim(substr($chan, 1)));
                     if ($chan != null) {
                         if (!$chan["private"]) {
                             if (!in_array($this->getUser()['_id'], $chan["banned"])) {
                                 $this->addChannel($chan["_id"]);
                                 $this->sendNumerical("332 {$this->nick} #{$chan["_id"]} :This is a public channel.");
                             } else {
                                 $this->sendNumerical("474 {$this->nick} :You are banned from this channel.");
                             }
                         } else {
                             if (Users::isRepoOwner($this->getUser()['_id'], $chan["_id"])) {
                                 $this->addChannel($chan["_id"]);
                                 $this->sendNumerical("332 {$this->nick} #{$chan["_id"]} :This is a private channel.");
                             } else {
                                 $this->sendNumerical("473 {$this->nick} :This is a private channel, you need an invite.");
                             }
                         }
                     } else {
                         $this->sendNumerical("403 {$this->nick} :That repository isn't registered with ShogChat.");
                     }
                 }
             }
             break;
         case "PRIVMSG":
             $chan = substr($msg[1], 1);
             if ($this->isMemberOf($chan)) {
                 if ($msg[2][0] == ":") {
                     $msg[2] = substr($msg[2], 1);
                     $msg[2] = implode(" ", array_slice($msg, 2));
                 }
                 $this->server->sendMessageToChannel($msg[2], $this, $chan);
                 $this->server->getChatServer()->sendMessageToChannel($msg[2], $this->ident, $chan);
             }
             break;
         case "PONG":
             //Nothing needed?
             break;
         case "QUIT":
             $this->close();
             break;
         case "PART":
             //TODO
             break;
         case "USERS":
             $this->sendNumerical("395 {$this->nick} :ShogChat can't display users in channel.");
             break;
         case "WHOIS":
             //TODO check nick
             $this->sendNumerical("311 {$this->nick} {$this->nick} {$this->ident} {$this->host} * :{$this->realName}");
             $this->sendNumerical("318 {$this->nick} {$this->nick} :End of /WHOIS list.");
             break;
         default:
             Logger::warning($msg[0] . " is an unrecognized IRC command.");
             break;
     }
 }