• Inloggen
  • Registreer
  • Zoeken
Dit topic
  • Overal
  • Dit topic
  • Dit forum
  • Artikelen
  • Pagina's
  • Forum
  • Downloads
  • Meer opties

ICTscripters

Dé plek voor IT

Dé plek voor IT

Aanmelden

Geavanceerde opties
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
    3. Onopgeloste topics
  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
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
    3. Onopgeloste topics
  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
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
    3. Onopgeloste topics
  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
  1. Dé plek voor IT - ICTscripters
  2. Forum
  3. Scripting & programmeren
  4. PHP + SQL

Forum

  • nieuwe game

    frio 1 november 2026 om 14:08
  • Criminolz

    qevanto 31 oktober 2026 om 20:52
  • [Beta] Ottomaan: gratis browserspel met een echte, levende stad. Feedback gezocht!

    frio 27 oktober 2026 om 12:22
  • Port Father: beta van een browsergame in Antwerpen 1931, feedback welkom

    Jeroen.G 26 oktober 2026 om 10:33
  • Maffia Hotel: een browsergame waarin je van lobbygast naar spil van het hotel groeit

    eeyk 22 oktober 2026 om 18:43
  • Crime Club volledig herschreven vanaf nul

    frio 19 oktober 2026 om 23:57
  • Malavita (nieuwe maffia game, van 0)

    jos 19 oktober 2026 om 23:18
  • Herkent deze Notion-structuurscan echte problemen?

    Jeroen.G 19 oktober 2026 om 15:09

Marktplaats

  • [Aanbod] Stadskaart voor je browsergame: van menu naar klikbare stad, vanaf €200

    frio 29 oktober 2026 om 18:17
  • [Verkoop] G4G (Gangsters 4 Gangsters): volledige broncode, nieuw gebouwd in PHP 8.3 | € 30 per domein

    frio 27 oktober 2026 om 18:54
  • [TE KOOP] Malavita.be [Maffiaspel, gebaseerd op omicidio.nl, unieke code]

    Dpm_x 26 oktober 2026 om 00:22

Voor wie een php irc bot wou beginnen

  • Patrick
  • 9 maart 2014 om 17:57
  • Patrick
    Back in the game
    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]);
    		}
    	}
    }
    ?>
    Meer tonen

    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).

  • Gast, wil je besparen op je domeinnamen? (ad)
  • Frenzo.Webservice
    Web Developer
    Berichten
    541
    • 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

    Helpt bedrijven met groeien :)

  • L. Velthuis
    Vato Gonzalez
    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
    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.

Registratie

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

Nu registreren Aanmelden

ICT Nieuws

  • PHP waarschuwt voor twee ernstige bugs die makkelijk uit te buiten lijken

    Aaron 22 oktober 2026 om 22:19

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
  1. Marktplaats
  2. Design
  3. Voorwaarden
  4. Ons team
  5. Leden
  6. Geschiedenis
  7. Regels
  8. Links
  9. Privacyverklaring
  10. Contact
ICTscripters ©2005 - 2026 , goedkope hosting door DiMoWeb.com, BE0558.915.582
Sponsors: Beste kattenhotel provincie Antwerpen
Style: Nexus by cls-design
Stylename
Nexus
Manufacturer
cls-design
Licence
Commercial styles
Help
Supportforum
Visit cls-design