• Login
  • Register
  • Zoek
This Thread
  • Everywhere
  • This Thread
  • This Forum
  • Articles
  • Pages
  • Forum
  • Filebase Entry
  • More Options

ICTscripters

Dé plek voor IT

Dé plek voor IT

Login

Geavanceerde opties
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
  3. ICT Nieuws
  4. Blog
  5. Marktplaats
    1. Werk
    2. Advertenties
    3. Domeinnamen
    4. Websites
    5. Design & lay-outs
    6. Scripts
    7. Overige
  6. Design
  7. Leden
    1. Actieve bezoekers
    2. Team
    3. Leden zoeken
  8. Downloads
  9. Goedkope domeinnamen
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
  3. ICT Nieuws
  4. Blog
  5. Marktplaats
    1. Werk
    2. Advertenties
    3. Domeinnamen
    4. Websites
    5. Design & lay-outs
    6. Scripts
    7. Overige
  6. Design
  7. Leden
    1. Actieve bezoekers
    2. Team
    3. Leden zoeken
  8. Downloads
  9. Goedkope domeinnamen
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
  3. ICT Nieuws
  4. Blog
  5. Marktplaats
    1. Werk
    2. Advertenties
    3. Domeinnamen
    4. Websites
    5. Design & lay-outs
    6. Scripts
    7. Overige
  6. Design
  7. Leden
    1. Actieve bezoekers
    2. Team
    3. Leden zoeken
  8. Downloads
  9. Goedkope domeinnamen
  1. Dé plek voor IT - ICTscripters
  2. Forum
  3. Scripting & programmeren
  4. PHP + SQL

Forum

  • Beta-testers gezocht voor Crypto-oefenplatform

    Syntax 29 januari 2026 om 16:11
  • Na 15 jaar terug van weggeweest: iCriminals.nl is terug (BETA)!

    Syntax 19 januari 2026 om 09:34
  • Developer Gezocht

    Mikevdk 10 januari 2026 om 18:57
  • Op zoek naar de legends

    Syntax 5 januari 2026 om 13:50
  • [FREE] WeFact Hosting module

    Jeroen.G 13 oktober 2025 om 14:09
  • Help testers nodig voor android app Urgent

    urgentotservices 26 september 2025 om 10:21
  • Versio vervanger

    Jeroen.G 25 augustus 2025 om 15:56
  • Afspraken systeem met planbeperking

    Lijno 1 augustus 2025 om 23:04

Marktplaats

  • 321 Nieuwe Domeinnamen December 2025

    shiga 1 januari 2026 om 10:26
  • Meerdere mafia game template te koop

    Syntax 26 december 2025 om 00:07
  • Van een pixelige afbeelding naar een strakke, moderne website

    Syntax 21 december 2025 om 17:05

Voor wie een php irc bot wou beginnen

  • Patrick
  • 9 maart 2014 om 17:57
  • Patrick
    Back in the game
    Ontvangen Reacties
    52
    Berichten
    1.417
    • 9 maart 2014 om 17:57
    • #1

    Zie hieronder :-):

    PHP
    <?php
    ini_set('max_execution_time', -1);
    
    
    class configuration {
    	
    	public $botConfig;
    	
    	public function __construct() {
    		$this->botConfig = array();
    	}
    	
    	public function createNewBot($hostname, $identity, $server, $realname, $nickname, $port, $domain) {
    		if (count($this->botConfig) == 0) {
    			$botConfigID = 0;
    		} else {
    			$botConfigID = count($this->botConfig);
    		}
    		$this->botConfig[$botConfigID]['hostname'] = $hostname;
    		$this->botConfig[$botConfigID]['identity'] = $identity;
    		$this->botConfig[$botConfigID]['server'] = $server;
    		$this->botConfig[$botConfigID]['realname'] = $realname;
    		$this->botConfig[$botConfigID]['nickname'] = $nickname;
    		$this->botConfig[$botConfigID]['port'] = $port;
    		$this->botConfig[$botConfigID]['domain'] = $domain;
    		
    		return $botConfigID;
    	}
    }
    
    
    class socket {
    	
    	public $sockets;
    	public $socketError;
    	
    	public function __construct() {
    		$this->sockets = array();
    		$this->socketError = array();
    	}
    	
    	public function create_socket($domain = 'ipv4') {
    		if ($domain == 'ipv6') { 
    			$this->sockets[] = socket_create(AF_INET6, SOCK_STREAM, SOL_TCP); 
    		} else { 
    			$this->sockets[] = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    		}
    		
    		$insertedArrayID = (count($this->sockets) - 1); 
    		if ($this->sockets[$insertedArrayID] == false) {
    			$this->$socketError[$insertedArrayID]['errorCode'] = socket_last_error($this->sockets[$insertedArrayID]);
    			$this->$socketError[$insertedArrayID]['errorMessage'] = socket_strerror($errorCode);
    			
    			socket_clear_error($this->sockets[$insertedArrayID]);
    			
    			return $socketError;
    		} else {
    			return $insertedArrayID;
    		}
    	}
    	
    	public function bind_socket($socketID = 0, $hostname) {
    		if (is_int($socketID)) {
    			
    			/* We can not make any more sockets until SO_REUSEPORT comes available on linux */
    			socket_set_option($this->sockets[$socketID], SOL_SOCKET, SO_REUSEADDR, 1);
    			
    			if (socket_bind($this->sockets[$socketID], $hostname, $this->configurationClass->botConfig[$socketID]['port']) == false) {
    				$this->$socketError[$socketID]['errorCode'] = socket_last_error($this->sockets[$socketID]);
    				$this->$socketError[$socketID]['errorMessage'] = socket_strerror($errorCode);
    			
    				socket_clear_error($this->sockets[$socketID]);
    			
    				return $socketError;
    			} else {
    				return true;
    			}
    		} else {
    			return false;
    		}
    	}
    	
    	public function connect_socket($socketID = 0, $ip, $port) {
    		if (is_int($socketID)) {
    			socket_connect($this->sockets[$socketID], $ip, $port);
    			
    			if ($this->sockets[$socketID] == false) {
    				$this-$socketError[$socketID]['errorCode'] = socket_last_error($this-$sockets[$socketID]);
    				$this-$socketError[$socketID]['errorMessage'] = socket_strerror($errorCode);
    			
    				socket_clear_error($this-$socket[$socketID]);
    			
    				return $socketError;
    			} else {
    				return true;
    			}
    		} else {
    			return false;
    		}
    	}
    	
    	public function write_socket($socketID = 0, $bufferData) {
    		if (is_int($socketID)) {
    			socket_write($this->sockets[$socketID], $bufferData . "\r\n");
    		} else {
    			return false;
    		}
    	}
    	
    	public function read_socket($socketID = 0) {
    		if (is_int($socketID)) {
    			$buffer = socket_read($this->sockets[$socketID], 65000, PHP_NORMAL_READ);
    			if ($buffer == '\n' OR $buffer == '\r') {
    				continue;
    			}
    			
    			return $buffer;
    		} else {
    			return false;
    		}	
    	}
    	
    	public function shutdown_socket($socketID = 0) {
    		if (is_int($socketID)) {
    			socket_shutdown($this->sockets[$socketID], 2);
    			
    			$this->close_socket[$socketID];
    		} else {
    			return false;
    		}
    	}
    	
    	protected function close_socket($socketID = 0) {
    		if (is_int($socketID)) {
    				socket_close($this->sockets[$socketID]);
    			return;
    		} else {
    			return false;
    		}	
    	}
    }
    
    
    class irc extends socket {
    	
    	private $configurationClass;
    	
    	public function setconfigrationClass($class) {
    		$this->configurationClass = $class;
    	}
    	
    	public function connectIRC($botID) {
    		$this->create_socket($this->configurationClass->botConfig[$botID]['domain']);
    		
    		$this->bind_socket($botID, $this->configurationClass->botConfig[$botID]['hostname'] . $botID);
    		$this->connect_socket($botID, $this->configurationClass->botConfig[$botID]['server'], $this->configurationClass->botConfig[$botID]['port']);
    		
    		$this->initIRCConnection($botID);
    		return true;
    	}
    	
    	protected function initIRCConnection($socketID = 0) {
    		$this->write_socket($socketID, 'USER ' . $this->configurationClass->botConfig[$socketID]['identity'] . ' ' .
    												   $this->configurationClass->botConfig[$socketID]['hostname'] . ' ' .
    												   $this->configurationClass->botConfig[$socketID]['server'] . ' :' .
    												   $this->configurationClass->botConfig[$socketID]['realname']);
    										
    		$this->write_socket($socketID, 'NICK ' . $this->configurationClass->botConfig[$socketID]['nickname']);
    		return true;
    	}
    	
    	public function playPingPong($socketID = 0, $pingID) {
    		$this->write_socket($socketID, 'PONG ' . $pingID);
    		return true;
    	}
    }
    
    
    $configurationClass = new configuration();
    $ircClass = new irc();
    
    
    $configurationClass->createNewBot(0, 'viibot', 'irc.onlinegamesnet.net', 'vii realname', 'viibot', 6667, 'ipv4');
    
    
    $ircClass->setconfigrationClass($configurationClass);
    foreach ($configurationClass->botConfig AS $bot => $botData) {
    	$ircClass->connectIRC($bot);
    }
    
    
    $i = 0;
    while (1) {
    	foreach ($configurationClass->botConfig AS $botID => $botData) {
    		
    		$usableID = intval($botID);
    		$bufferData = $ircClass->read_socket($usableID);
    		$splitBuffer = split(' ', $bufferData);
    		
    		if ($splitBuffer[0] = 'PING') {
    			$ircClass->playPingPong($usableID, $splitBuffer[1]);
    		}
    	}
    }
    ?>
    Toon Meer

    Ik ga hem zelf rebuilden met het gebruik met pcntl_fork :-).
    Enige wat de bot nu kan is connecten naar een irc server en idle'en :-).

    in de while (1) { } loop zal je het een en ander nog wel zelf moeten defineren aan commands :).
    Let op: ondanks dat er wel de functionaliteit in zit dat er meerdere sockets te gelijk kunnen opereren binnen script kan het nu niet dat 2 bots over de zelfde port luisteren (Standaard 6667).

  • Guest, wil je besparen op je domeinnamen? (ad)
  • Frenzo.Brouwer
    Web Developer
    Ontvangen Reacties
    35
    Berichten
    535
    • 10 maart 2014 om 11:18
    • #2

    Zou je ook misschien kunnen uitleggen voor de mensen zoals ik die niet weten wat het is?

    Gr,
    Frenzo

    Eigenaar van:
    Online Marketing & Webdesign Bureau - https://marketingmetrics.nl/
    Gaming Plaform - https://onetwogaming.nl/
    Banditi - https://banditi.nl/
    Criminas - https://criminas.nl/

  • L. Velthuis
    Vato Gonzalez
    Ontvangen Reacties
    32
    Berichten
    682
    • 10 maart 2014 om 11:49
    • #3

    Ook ik zou graag weten wat het is. en wat je er mee zou kunnen doen.

    Beginnend DJ! Volg mij op MixCloud!

    Lars Velthuis | Mixcloud

  • Patrick
    Back in the game
    Ontvangen Reacties
    52
    Berichten
    1.417
    • 10 maart 2014 om 17:32
    • #4

    IRC is een chat protocol waarmee je in verschillende kanalen kan chatten deze kan je ook beheren etc.
    Doormiddel van een automatisering bot kan je bepaalde kanaal handeling makkelijker doen of kan in de chat bijv:

    !imdb the hobbit

    doen en krijg je informatie over die film. (voorbeeld uiteraard zit niet hierin)
    Het script is basis programmering om een "geautomatiseerde user" te beginnen waarmee je zulke dingen kan bereiken.

Participate now!

Heb je nog geen account? Registreer je nu en word deel van onze community!

Maak een account aan Login

ICT Nieuws

  • Fijne feestdagen

    tcbhome 28 december 2025 om 13:55
  • Kritieke update voor Really Simple Security-plug-in

    K.Rens 16 november 2024 om 16:12
  • ING Nederland streeft naar ondersteuning van Google Pay tegen eind februari

    K.Rens 2 november 2024 om 16:09

Blogs

  • Functioneel ontwerp

    Dees 28 december 2014 om 12:38
  • Access Control List implementatie in PHP/MySQL - deel 1/2

    FangorN 28 december 2018 om 12:35
  • Access Control List implementatie in PHP/MySQL - deel 2/2

    FangorN 29 december 2018 om 12:37

Gebruikers die dit topic bekijken

  • 1 Gasten
  1. Marktplaats
  2. Design
  3. Voorwaarden
  4. Ons team
  5. Leden
  6. Geschiedenis
  7. Regels
  8. Links
  9. Privacy Policy
ICTscripters ©2005 - 2026 , goedkope hosting door DiMoWeb.com, BE0558.915.582
Sponsors: Beste kattenhotel provincie Antwerpen | Beste Zetes eid kaartlezer webshop
Style: Nexus by cls-design
Stylename
Nexus
Manufacturer
cls-design
Licence
Commercial styles
Help
Supportforum
Visit cls-design