fix
This commit is contained in:
parent
b29ae43dd6
commit
66599bc6bd
8
C/irc.c
8
C/irc.c
@ -1,8 +1,8 @@
|
||||
#include "irc.h"
|
||||
|
||||
unsigned int IRCC_connect(IRCC_client *irc, const char *ip, const unsigned int port){
|
||||
struct hostent *ghbn = gethostbyname(ip);
|
||||
if (!ghbn)
|
||||
struct hostent *hp = gethostbyname(ip);
|
||||
if (!hp)
|
||||
return IRCC_ERROR;
|
||||
|
||||
//Only ipv4
|
||||
@ -10,7 +10,7 @@ unsigned int IRCC_connect(IRCC_client *irc, const char *ip, const unsigned int p
|
||||
memset(&client_str, 0, sizeof(client_str));
|
||||
client_str.sin_family = AF_INET;
|
||||
client_str.sin_port = htons(port);
|
||||
client_str.sin_addr.s_addr = inet_addr(inet_ntoa(*(struct in_addr *)ghbn->h_addr));
|
||||
client_str.sin_addr.s_addr = inet_addr(inet_ntoa(*(struct in_addr *)hp->h_addr));
|
||||
|
||||
irc->socket = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (irc->socket < 0)
|
||||
@ -79,7 +79,7 @@ unsigned int IRCC_recv(IRCC_client *irc){
|
||||
}
|
||||
|
||||
else {
|
||||
//puts(irc->raw);
|
||||
puts(irc->raw);
|
||||
|
||||
//Check end of motd
|
||||
if (strstr(irc->raw, "PRIVMSG ") == NULL && strstr(irc->raw, "MOTD"))
|
||||
|
4
C/irc.h
4
C/irc.h
@ -8,10 +8,6 @@
|
||||
motd parsing
|
||||
*/
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#error "Only unix"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
9
LICENSE
Normal file
9
LICENSE
Normal file
@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) <year> <copyright holders>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
Python/README.md
Normal file
1
Python/README.md
Normal file
@ -0,0 +1 @@
|
||||
Delete me
|
55
Python/irc.py
Normal file
55
Python/irc.py
Normal file
@ -0,0 +1,55 @@
|
||||
import socket
|
||||
import time
|
||||
import sys
|
||||
|
||||
class IRC:
|
||||
def __init__(self, channel, code):
|
||||
self.channel = channel
|
||||
self.sock = socket.socket()
|
||||
self.code = code
|
||||
|
||||
self.sender = {"ip":"", "nickname":""}
|
||||
self.data = {"type":""}
|
||||
|
||||
def connect(self, host, nick):
|
||||
self.sock.connect(host)
|
||||
|
||||
self.sock.send(f"USER {nick} 0 0 {nick}\r\n".encode(self.code))
|
||||
self.sock.send(f"NICK {nick}\r\n".encode(self.code))
|
||||
time.sleep(7)
|
||||
self.sock.send(f"JOIN {self.channel}\r\n".encode(self.code))
|
||||
|
||||
def recv(self, size):
|
||||
try:
|
||||
data = self.sock.recv(size).decode()
|
||||
except UnicodeDecodeError:
|
||||
return None
|
||||
|
||||
if len(data) == 0:
|
||||
self.sock.close()
|
||||
raise BrokenPipeError("Disconnected")
|
||||
|
||||
if "PING" in data.split(":")[0]:
|
||||
self.sock.send(f"PONG {data.split()[-1]}\r\n".encode())
|
||||
return data
|
||||
|
||||
def parser(self, data):
|
||||
data = data.split(" ", 3)
|
||||
self.sender["ip"] = data[0].split("@", 1)[-1]
|
||||
self.sender["nickname"] = data[0].split("!", 1)[0][1:]
|
||||
|
||||
if data[1] == "PRIVMSG":
|
||||
self.data["channel"] = data[2]
|
||||
self.data["msg"] = data[-1][1:].strip()
|
||||
self.data["type"] = "PRIVMSG"
|
||||
|
||||
elif data[1] == "JOIN":
|
||||
self.data["type"] = "JOIN"
|
||||
elif data[1] == "PART":
|
||||
self.data["type"] = "PART"
|
||||
|
||||
def sendMSG(self, msg, channel):
|
||||
self.sock.send(f"PRIVMSG {channel} :{msg}\r\n".encode(self.code))
|
||||
|
||||
def sendRAW(self, msg):
|
||||
self.sock.send(f"{msg}\r\n".encode(self.code))
|
28
Python/main.py
Normal file
28
Python/main.py
Normal file
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/python3
|
||||
import sys
|
||||
import time
|
||||
from irc import IRC
|
||||
|
||||
def main():
|
||||
main = IRC("#mainchannel", "cp1251")
|
||||
main.connect(("irc..ru", 6667), "tester")
|
||||
|
||||
while True:
|
||||
data = main.recv(512)
|
||||
if data is None:
|
||||
continue
|
||||
|
||||
main.parser(data)
|
||||
print(main.sender)
|
||||
print(main.data)
|
||||
|
||||
if __name__ == "__main__":
|
||||
while True:
|
||||
try:
|
||||
main()
|
||||
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
|
||||
except:
|
||||
pass
|
Loading…
Reference in New Issue
Block a user