1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-13 03:00:42 +00:00
OpenDiablo2/d2networking/d2client/d2client.go
dk fe47e51351
Refactor d2map (#468)
* WIP refactor of d2map stuff

* more d2map refactor

adding realm init to game client
passing map engine from client and server into realm at init
change `generate map packet` to have act and level index as data

* client explodes, but getting there

* realm now initializes, networking works, but map generators dont currently do anything

* changed the way that level type records are loaded

* fixed funcs for level data lookups

* started implementing level generator, currently crashing

* client no longer exploding

* d2networking refactor

put exports into d2client.go and d2server.go
kept GameClient and GameServer methods into their respective files
made methods for packet handlers instead of the giant switch statements

* bugfix: getting first level id by act

* minor refactor of gamescreen for readability

* towns now generate on server start, create player takes act and level id as args, levels have their own map engine
2020-06-26 16:50:24 -04:00

39 lines
1.3 KiB
Go

package d2client
import (
"fmt"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapengine"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapentity"
d2cct "github.com/OpenDiablo2/OpenDiablo2/d2networking/d2client/d2clientconnectiontype"
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2client/d2localclient"
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2client/d2remoteclient"
)
// Creates a connections to the server and returns a game client instance
func Create(connectionType d2cct.ClientConnectionType) (*GameClient, error) {
result := &GameClient{
// TODO: Mapgen - Needs levels.txt stuff
MapEngine: d2mapengine.CreateMapEngine(),
Players: make(map[string]*d2mapentity.Player),
connectionType: connectionType,
realm: &d2mapengine.MapRealm{},
}
switch connectionType {
case d2cct.LANClient:
result.clientConnection = d2remoteclient.Create()
case d2cct.LANServer:
openSocket := true
result.clientConnection = d2localclient.Create(openSocket)
case d2cct.Local:
dontOpenSocket := false
result.clientConnection = d2localclient.Create(dontOpenSocket)
default:
str := "unknown client connection type specified: %d"
return nil, fmt.Errorf(str, connectionType)
}
result.clientConnection.SetClientListener(result)
return result, nil
}