-
-
Notifications
You must be signed in to change notification settings - Fork 22
SQL Features
Gopher's SQL features will enable you to use all the database
package's functionalities:
- Account creation
- Logging users in with their account name, password, and any custom checks
- Auto-login with generated secure keys
- Custom account information
- Friending
If you do not wish to use the SQL features, you will need to implement your own mechanisms for the features listed above.
Before you can use the SQL features, you will need a MySQL or similar database installed and running on your system. You can acquire the latest version of MySQL at: www.mysql.com
Once you've installed and ran SQL database, you will need to make a new user that Gopher will use to log into the database with. Make sure the user has the following privileges granted: SELECT
, INSERT
, UPDATE
, DELETE
, EXECUTE
, CREATE
, ALTER
, REFERENCES
, and DROP
. You also will need to know the following information about your database for later: IP address, port number, and network protocol. If you haven't done so already, make a database where Gopher can create it's tables.
Now, with all this information you can set the required entries in gopher.ServerSettings
to enable the SQL features:
package main
import (
"github.com/hewiefreeman/GopherGameServer"
)
func main() {
settings := gopher.ServerSettings{
ServerName: "!s!",
MaxConnections: 10000,
HostName: "http://example.com",
HostAlias: "http://www.example.com",
IP: "192.168.1.1",
Port: 8080,
OriginOnly: true,
// Using a TLS/SSL connection is highly recommended when using SQL features!
TLS: true,
CertFile: "C:/path/to/certificate.pem",
PrivKeyFile: "C:/path/to/privkey.pem",
// Enable SQL features
SqlIP: "localhost",
SqlPort: 3306,
SqlProtocol: "tcp",
SqlUser: "userName",
SqlPassword: "password",
SqlDatabase: "databaseName",
}
gopher.Start(&settings)
}
Warning: As stated in the above comment, it is highly recommended to use an encrypted TLS/SSL connection when using the SQL features, or sensitive account information can be compromised with network "snooping" (AKA "sniffing"). If you are not using an encrypted connection and do not know where to start, you can start by acquiring a free SSL certificate from Let's Encrypt and reading their (or your web/cloud hosting provider's) documentation and help sections.
Gopher server and the client APIs will take care of most of the work from here. With the above entries in ServerSettings
set, Gopher will now use the database to log clients in, enable clients to sign-up, and enable friending. A client will be required to sign-up before logging in unless they log in as a guest. It is highly recommended to not use the users.Login()
function, and now rely on the client API to send built-in commands, and let Gopher take care of the rest.
Check out your client API documentation to learn how to send the built-in sign up, log in, log out, etc commands from there.
If you notice there is lacking information, missing features, or bad explanations, please open an issue. All requests are acceptable and will be taken into consideration.