Skip to content

SetLoginCallback throws nil pointer dereference #6

Open

Description

@perling1

Whenever i set the SetLoginCallback function, i get a runtime fatal panic

panic: runtime error: invalid memory address or nil pointer dereference
github.com/hewiefreeman/GopherGameServer.SetLoginCallback({0xed0fa0, 0xf327a8})
C:/Users/mbd/go/pkg/mod/github.com/hewiefreeman/!gopher!game!server@v0.0.0-20211216002529-88cc3fabb02c/callbacks.go:125 +0xc2

Is it because there is no database initialized? You can recreate the error with:

func main() {
	settings := gopher.ServerSettings{
		ServerName:     "myserv01",
		MaxConnections: 6,

		HostName:  "localhost",
		HostAlias: "localhost",
		IP:        "localhost",
		Port:      8080,

		TLS:         false,
		CertFile:    "",
		PrivKeyFile: "",

		OriginOnly: false,

		MultiConnect:   false,
		KickDupOnLogin: false,

		UserRoomControl:   true,
		RoomDeleteOnLeave: true,

		EnableSqlFeatures: false,
		SqlIP:             "localhost",
		SqlPort:           3306,
		SqlProtocol:       "tcp",
		SqlUser:           "user",
		SqlPassword:       "password",
		SqlDatabase:       "database",
		EncryptionCost:    4,
		CustomLoginColumn: "",
		RememberMe:        false,

		EnableRecovery:   false,
		RecoveryLocation: "C:/",
		AdminLogin:       "admin",
		AdminPassword:    "1234",
	}

 setErrs := gopher.SetLoginCallback(clientLoggedIn)
	if setErrs != nil {
		fmt.Println(setErrs)
	}
gopher.Start(&settings)
}


func clientLoggedIn(userName string, databaseID int, receivedColumns map[string]interface{}, clientColumns map[string]interface{}) bool {
	fmt.Println("Entered")
	return true
}

Activity

  1. perling1 commented on Feb 13, 2022

    @perling1
    Author

    To give more insight, the callback onlogout works as described. It doesnt throw a nil pointer panic.

    func main() {
    	settings := gopher.ServerSettings{
    		ServerName:     "myserv01",
    		MaxConnections: 6,
    
    		HostName:  "localhost",
    		HostAlias: "localhost",
    		IP:        "localhost",
    		Port:      8080,
    
    		TLS:         false,
    		CertFile:    "",
    		PrivKeyFile: "",
    
    		OriginOnly: false,
    
    		MultiConnect:   false,
    		KickDupOnLogin: false,
    
    		UserRoomControl:   true,
    		RoomDeleteOnLeave: true,
    
    		EnableSqlFeatures: false,
    		SqlIP:             "localhost",
    		SqlPort:           3306,
    		SqlProtocol:       "tcp",
    		SqlUser:           "user",
    		SqlPassword:       "password",
    		SqlDatabase:       "database",
    		EncryptionCost:    4,
    		CustomLoginColumn: "",
    		RememberMe:        false,
    		EnableRecovery:   false,
    		RecoveryLocation: "C:/",
    		AdminLogin:       "admin",
    		AdminPassword:    "1234",
    	}
    	setErrs := gopher.SetLogoutCallback(clientLoggedOut)
    	if setErrs != nil {
    		fmt.Println(setErrs)
    	}
    	gopher.Start(&settings)
    }
    
    func clientLoggedOut(userName string, databaseID int) {
    	fmt.Println("Entered")
    }
    

    The nil pointer comes from line125 in callbacks.go
    its the only line of code that tries to access the setting by *

    if (*settings).EnableSqlFeatures {

  2. hewiefreeman commented on Feb 14, 2022

    @hewiefreeman
    Owner

    Oh, this is an interesting problem. Thanks for bringing it to my attention! It seems there was an oversight on the flow of starting the server. For now, you could make a method UpdateSettings(s *ServerSettings) in server.go that replaces the // Set server settings potion of the Start() function (just cut-paste into the new function). Then you can update the settings before calling SetLogoutCallback() or anything else that needs it before starting. I just don't have the time to get around to this for a day or so.

  3. perling1 commented on Feb 14, 2022

    @perling1
    Author

    Another problem is golang cant include pullrequests from github modules.
    I have modified the server.go, but i cant get it loaded in my project as its not a "master" oder "stable" version.

  4. hewiefreeman commented on Feb 15, 2022

    @hewiefreeman
    Owner

    This project hasn't been set up with go modules. At least not yet. I've been able to use GGS along with other Go APIs without modules. Are you sure your project is in the right gopath to prevent it from using modules?

  5. perling1 commented on Feb 15, 2022

    @perling1
    Author

    I was maybe to unspecific. I use a go.mod file with my own fork

    go.mod
    require (
    	github.com/perling1/GopherGameServer v0.0.0-20220214170824-f4a7d5e6619a // indirect
    )
    

    In the main testserver.go file:

    import (
    ...	
    gopher "github.com/perling1/GopherGameServer"
    	"github.com/perling1/GopherGameServer/actions"
    	"github.com/perling1/GopherGameServer/core"
    )
    ..
           gopher.UpdateServerSettings(&settings)
    	setErrs = gopher.SetLoginCallback(clientLoggedIn)
    
    

    Because if i import your GGS github.com/hewiefreeman/GopherGameServer/
    my pullrequest wasnt imported , so the func "gopher.UpdateServerSettings(&settings) " didnt exist.

    Its a big hassle to import "github libs" that change. you have to use terminal commands to reset caches
    go mod -clean
    go mod tidy
    go get github.com/perling1/GopherGameServer@master

    Thats an annoying act while using "go and mod". Its not due to your project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions