Index: /trunk/db.go
===================================================================
--- /trunk/db.go	(revision 262)
+++ /trunk/db.go	(revision 263)
@@ -4,4 +4,5 @@
 	"database/sql"
 	"fmt"
+	"strings"
 	"sync"
 
@@ -24,12 +25,13 @@
 
 type Network struct {
-	ID       int64
-	Name     string
-	Addr     string
-	Nick     string
-	Username string
-	Realname string
-	Pass     string
-	SASL     SASL
+	ID              int64
+	Name            string
+	Addr            string
+	Nick            string
+	Username        string
+	Realname        string
+	Pass            string
+	ConnectCommands []string
+	SASL            SASL
 }
 
@@ -64,4 +66,5 @@
 	realname VARCHAR(255),
 	pass VARCHAR(255),
+	connect_commands VARCHAR(1023),
 	sasl_mechanism VARCHAR(255),
 	sasl_plain_username VARCHAR(255),
@@ -83,4 +86,5 @@
 var migrations = []string{
 	"", // migration #0 is reserved for schema initialization
+	"ALTER TABLE Network ADD COLUMN connect_commands VARCHAR(1023)",
 }
 
@@ -234,5 +238,5 @@
 
 	rows, err := db.db.Query(`SELECT id, name, addr, nick, username, realname, pass,
-			sasl_mechanism, sasl_plain_username, sasl_plain_password
+			connect_commands, sasl_mechanism, sasl_plain_username, sasl_plain_password
 		FROM Network
 		WHERE user = ?`,
@@ -246,8 +250,8 @@
 	for rows.Next() {
 		var net Network
-		var name, username, realname, pass *string
+		var name, username, realname, pass, connectCommands *string
 		var saslMechanism, saslPlainUsername, saslPlainPassword *string
 		err := rows.Scan(&net.ID, &name, &net.Addr, &net.Nick, &username, &realname,
-			&pass, &saslMechanism, &saslPlainUsername, &saslPlainPassword)
+			&pass, &connectCommands, &saslMechanism, &saslPlainUsername, &saslPlainPassword)
 		if err != nil {
 			return nil, err
@@ -257,4 +261,7 @@
 		net.Realname = fromStringPtr(realname)
 		net.Pass = fromStringPtr(pass)
+		if connectCommands != nil {
+			net.ConnectCommands = strings.Split(*connectCommands, "\r\n")
+		}
 		net.SASL.Mechanism = fromStringPtr(saslMechanism)
 		net.SASL.Plain.Username = fromStringPtr(saslPlainUsername)
@@ -277,4 +284,5 @@
 	realname := toStringPtr(network.Realname)
 	pass := toStringPtr(network.Pass)
+	connectCommands := toStringPtr(strings.Join(network.ConnectCommands, "\r\n"))
 
 	var saslMechanism, saslPlainUsername, saslPlainPassword *string
@@ -293,16 +301,16 @@
 	if network.ID != 0 {
 		_, err = db.db.Exec(`UPDATE Network
-			SET name = ?, addr = ?, nick = ?, username = ?, realname = ?, pass = ?,
+			SET name = ?, addr = ?, nick = ?, username = ?, realname = ?, pass = ?, connect_commands = ?,
 				sasl_mechanism = ?, sasl_plain_username = ?, sasl_plain_password = ?
 			WHERE id = ?`,
-			netName, network.Addr, network.Nick, netUsername, realname, pass,
+			netName, network.Addr, network.Nick, netUsername, realname, pass, connectCommands,
 			saslMechanism, saslPlainUsername, saslPlainPassword, network.ID)
 	} else {
 		var res sql.Result
 		res, err = db.db.Exec(`INSERT INTO Network(user, name, addr, nick, username,
-				realname, pass, sasl_mechanism, sasl_plain_username,
+				realname, pass, connect_commands, sasl_mechanism, sasl_plain_username,
 				sasl_plain_password)
-			VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
-			username, netName, network.Addr, network.Nick, netUsername, realname, pass,
+			VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
+			username, netName, network.Addr, network.Nick, netUsername, realname, pass, connectCommands,
 			saslMechanism, saslPlainUsername, saslPlainPassword)
 		if err != nil {
Index: /trunk/service.go
===================================================================
--- /trunk/service.go	(revision 262)
+++ /trunk/service.go	(revision 263)
@@ -105,5 +105,5 @@
 			children: serviceCommandSet{
 				"create": {
-					usage:  "-addr <addr> [-name name] [-username username] [-pass pass] [-realname realname] [-nick nick]",
+					usage:  "-addr <addr> [-name name] [-username username] [-pass pass] [-realname realname] [-nick nick] [[-connect-command command] ...]",
 					desc:   "add a new network",
 					handle: handleServiceCreateNetwork,
@@ -175,4 +175,15 @@
 }
 
+type stringSliceVar []string
+
+func (v *stringSliceVar) String() string {
+	return fmt.Sprint([]string(*v))
+}
+
+func (v *stringSliceVar) Set(s string) error {
+	*v = append(*v, s)
+	return nil
+}
+
 func handleServiceCreateNetwork(dc *downstreamConn, params []string) error {
 	fs := newFlagSet()
@@ -183,4 +194,6 @@
 	realname := fs.String("realname", "", "")
 	nick := fs.String("nick", "", "")
+	var connectCommands stringSliceVar
+	fs.Var(&connectCommands, "connect-command", "")
 
 	if err := fs.Parse(params); err != nil {
@@ -191,4 +204,11 @@
 	}
 
+	for _, command := range connectCommands {
+		_, err := irc.ParseMessage(command)
+		if err != nil {
+			return fmt.Errorf("flag -connect-command must be a valid raw irc command string: %q: %v", command, err)
+		}
+	}
+
 	if *nick == "" {
 		*nick = dc.nick
@@ -197,10 +217,11 @@
 	var err error
 	network, err := dc.user.createNetwork(&Network{
-		Addr:     *addr,
-		Name:     *name,
-		Username: *username,
-		Pass:     *pass,
-		Realname: *realname,
-		Nick:     *nick,
+		Addr:            *addr,
+		Name:            *name,
+		Username:        *username,
+		Pass:            *pass,
+		Realname:        *realname,
+		Nick:            *nick,
+		ConnectCommands: connectCommands,
 	})
 	if err != nil {
Index: /trunk/upstream.go
===================================================================
--- /trunk/upstream.go	(revision 262)
+++ /trunk/upstream.go	(revision 263)
@@ -1190,4 +1190,13 @@
 	}
 
+	for _, command := range uc.network.ConnectCommands {
+		m, err := irc.ParseMessage(command)
+		if err != nil {
+			uc.logger.Printf("failed to parse connect command %q: %v", command, err)
+		} else {
+			uc.SendMessage(m)
+		}
+	}
+
 	return nil
 }
