acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
IRC.cpp (2281B)
1 #include "IRC.h" 2 3 4 unsigned long joinChannelTime = 0; 5 bool readyToJoinChannel = false; 6 7 WiFiClient* client; 8 9 10 void action(String target, String message) { 11 sendIRC("PRIVMSG " + String(target) + " :\001ACTION " + message + "\001"); 12 } 13 14 15 bool connectToIRC() { 16 if (irc_tls) { 17 Serial.println("Connecting to IRC with TLS: " + String(irc_server) + ":" + String(irc_port)); 18 client = new WiFiClientSecure(); 19 static_cast<WiFiClientSecure*>(client)->setInsecure(); 20 return static_cast<WiFiClientSecure*>(client)->connect(irc_server.c_str(), irc_port); 21 } else { 22 Serial.println("Connecting to IRC: " + String(irc_server) + ":" + String(irc_port)); 23 client = new WiFiClient(); 24 return client->connect(irc_server.c_str(), irc_port); 25 } 26 } 27 28 29 void handleIRC() { 30 while (client->available()) { 31 String line = client->readStringUntil('\n'); 32 33 if (line.length() > 512) { 34 Serial.println("WARNING: IRC line length exceeds 512 characters!"); 35 line = line.substring(0, 512); 36 } 37 38 Serial.println("IRC: " + line); 39 40 int firstSpace = line.indexOf(' '); 41 int secondSpace = line.indexOf(' ', firstSpace + 1); 42 43 if (firstSpace != -1 && secondSpace != -1) { 44 String prefix = line.substring(0, firstSpace); 45 String command = line.substring(firstSpace + 1, secondSpace); 46 47 if (command == "001") { 48 joinChannelTime = millis() + 2500; 49 readyToJoinChannel = true; 50 } 51 } 52 53 if (line.startsWith("PING")) { 54 String pingResponse = "PONG " + line.substring(line.indexOf(' ') + 1); 55 sendIRC(pingResponse); 56 } else { 57 parseAndDisplay(line); 58 lastActivityTime = millis(); 59 } 60 } 61 } 62 63 64 void sendIRC(String command) { 65 if (command.length() > 510) { 66 Serial.println("Failed to send: Command too long"); 67 return; 68 } 69 70 if (client->connected()) { 71 if (client->println(command)) { 72 Serial.println("IRC: >>> " + command); 73 } else { 74 Serial.println("Failed to send: " + command); 75 } 76 } else { 77 Serial.println("Failed to send: Not connected to IRC"); 78 } 79 } 80 81