X-Git-Url: http://www.git.cypherpunks.ru/?p=goircd.git;a=blobdiff_plain;f=daemon.go;h=53dde3eedbe93282cabefda26fcbde482b61f10d;hp=ed708de9875a7b054f27e5a27bfad6e122ad90d3;hb=3016635f6a6bd23e34461e93cef3e8d861ce4275;hpb=8702ace766119effc2c2ec4afa284bec6f24c4da diff --git a/daemon.go b/daemon.go index ed708de..53dde3e 100644 --- a/daemon.go +++ b/daemon.go @@ -1,6 +1,6 @@ /* goircd -- minimalistic simple Internet Relay Chat (IRC) server -Copyright (C) 2014 Sergey Matveev +Copyright (C) 2014-2015 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,6 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ + package main import ( @@ -29,9 +30,12 @@ import ( ) const ( - PingTimeout = time.Second * 180 // Max time deadline for client's unresponsiveness - PingThreshold = time.Second * 90 // Max idle client's time before PING are sent - AlivenessCheck = time.Second * 10 // Client's aliveness check period + // Max time deadline for client's unresponsiveness + PingTimeout = time.Second * 180 + // Max idle client's time before PING are sent + PingThreshold = time.Second * 90 + // Client's aliveness check period + AlivenessCheck = time.Second * 10 ) var ( @@ -54,7 +58,12 @@ type Daemon struct { } func NewDaemon(version string, hostname, motd, passwords *string, logSink chan<- LogEvent, stateSink chan<- StateEvent) *Daemon { - daemon := Daemon{version: version, hostname: hostname, motd: motd, passwords: passwords} + daemon := Daemon{ + version: version, + hostname: hostname, + motd: motd, + passwords: passwords, + } daemon.clients = make(map[*Client]bool) daemon.clientAliveness = make(map[*Client]*ClientAlivenessState) daemon.rooms = make(map[string]*Room) @@ -171,6 +180,8 @@ func (daemon *Daemon) ClientRegister(client *Client, command string, cols []stri return } nickname := cols[1] + // Compatibility with some clients prepending colons to nickname + nickname = strings.TrimPrefix(nickname, ":") for existingClient := range daemon.clients { if existingClient.nickname == nickname { client.ReplyParts("433", "*", nickname, "Nickname is already in use") @@ -324,7 +335,10 @@ func (daemon *Daemon) Processor(events <-chan ClientEvent) { switch event.eventType { case EventNew: daemon.clients[client] = true - daemon.clientAliveness[client] = &ClientAlivenessState{pingSent: false, timestamp: now} + daemon.clientAliveness[client] = &ClientAlivenessState{ + pingSent: false, + timestamp: now, + } case EventDel: delete(daemon.clients, client) delete(daemon.clientAliveness, client) @@ -445,7 +459,11 @@ func (daemon *Daemon) Processor(events <-chan ClientEvent) { if !found { client.ReplyNoNickChan(target) } - daemon.roomSinks[r] <- ClientEvent{client, EventMsg, command + " " + strings.TrimLeft(cols[1], ":")} + daemon.roomSinks[r] <- ClientEvent{ + client, + EventMsg, + command + " " + strings.TrimLeft(cols[1], ":"), + } case "TOPIC": if len(cols) == 1 { client.ReplyNotEnoughParameters("TOPIC")