Initial converter

master
HimbeerserverDE 2021-04-21 15:26:29 +02:00
parent 693a723af3
commit 7ab774c8f9
No known key found for this signature in database
GPG Key ID: 1A651504791E6A8B
4 changed files with 98 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
multiserver_converter

90
converter.go Normal file
View File

@ -0,0 +1,90 @@
/*
multiserver_converter is a utility designed to convert MT authentication
databases to the multiserver authentication database scheme
Usage:
multiserver_converter <in> <out>
where in is the path to the MT auth database
and out is the desired path to the newly created database
*/
package main
import (
"database/sql"
"errors"
"fmt"
"os"
_ "github.com/mattn/go-sqlite3"
)
func convertDB(in, out string) error {
db, err := sql.Open("sqlite3", in)
if err != nil {
return err
}
defer db.Close()
db2, err := sql.Open("sqlite3", out)
if err != nil {
return err
}
defer db2.Close()
if _, err := db2.Exec(`
CREATE TABLE auth (
name VARCHAR(32) NOT NULL,
password VARCHAR(512) NOT NULL
);
CREATE TABLE privileges (
name VARCHAR(32) NOT NULL,
privileges VARCHAR(1024)
);
CREATE TABLE ban (
addr VARCHAR(39) NOT NULL,
name VARCHAR(32) NOT NULL
);`); err != nil {
return err
}
result := db.QueryRow("SELECT name, password FROM auth;")
for {
var name, password string
err := result.Scan(&name, &password)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
break
}
return err
}
_, err = db2.Exec(`INSERT INTO auth (
name, password
) VALUES (
?,
?
);`, name, password)
if err != nil {
return err
}
}
return nil
}
func main() {
if len(os.Args) != 3 {
fmt.Println("Usage: multiserver_converter <in> <out>")
os.Exit(1)
}
if err := convertDB(os.Args[1], os.Args[2]); err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Database converted successfully")
}

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module github.com/HimbeerserverDE/multiserver/multiserver_converter
go 1.16
require github.com/mattn/go-sqlite3 v1.14.7

2
go.sum Normal file
View File

@ -0,0 +1,2 @@
github.com/mattn/go-sqlite3 v1.14.7 h1:fxWBnXkxfM6sRiuH3bqJ4CfzZojMOLVc0UTsTglEghA=
github.com/mattn/go-sqlite3 v1.14.7/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=