Skip to content

Commit

Permalink
111
Browse files Browse the repository at this point in the history
  • Loading branch information
bobohume committed Mar 4, 2021
1 parent 3f8c77b commit 960fb92
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 37 deletions.
1 change: 1 addition & 0 deletions base/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func Clamp(val, low, high int) int {

func IFAssert(x bool, y string) {
if bool(x) == false {
GLOG.Fatalf("\nFatal :{%s}", y)
log.Fatalf("\nFatal :{%s}", y)
}
}
Expand Down
64 changes: 34 additions & 30 deletions base/datafile.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const(

type(
RData struct{
m_FileName string
m_Type int

m_String string
Expand All @@ -52,6 +53,7 @@ type(
RecordNum int//记录数量
ColumNum int//列数量

fileName string//文件名
fstream *BitStream
readstep int//控制读的总数量
dataTypes vector.Vector
Expand All @@ -75,6 +77,7 @@ func (this *CDataFile) ReadDataInit(){
func (this *CDataFile) ReadDataFile(fileName string) bool{
this.dataTypes.Clear()
this.currentColumnIndex = 0
this.fileName = fileName

file, err := os.Open(fileName)
if err != nil {
Expand Down Expand Up @@ -128,6 +131,7 @@ func (this *CDataFile) GetData(pData *RData) bool {
return false
}

pData.m_FileName = this.fileName
switch this.dataTypes.Get(this.currentColumnIndex).(int) {
case DType_String:
pData.m_String = this.fstream.ReadString()
Expand Down Expand Up @@ -199,77 +203,77 @@ func (this *CDataFile) GetData(pData *RData) bool {
/****************************
RData funciton
****************************/
func (this *RData) String(dataname, datacol string) string{
IFAssert(this.m_Type == DType_String, fmt.Sprintf("read [%s] col[%s] error", dataname, datacol))
func (this *RData) String(datacol string) string{
IFAssert(this.m_Type == DType_String, fmt.Sprintf("read [%s] col[%s] error", this.m_FileName, datacol))
return this.m_String
}

func (this *RData) Enum(dataname, datacol string) int{
IFAssert(this.m_Type == DType_Enum, fmt.Sprintf("read [%s] col[%s] error", dataname, datacol))
func (this *RData) Enum(datacol string) int{
IFAssert(this.m_Type == DType_Enum, fmt.Sprintf("read [%s] col[%s] error", this.m_FileName, datacol))
return this.m_Enum
}

func (this *RData) Int8(dataname, datacol string) int8{
IFAssert(this.m_Type == DType_S8, fmt.Sprintf("read [%s] col[%s] error", dataname, datacol))
func (this *RData) Int8(datacol string) int8{
IFAssert(this.m_Type == DType_S8, fmt.Sprintf("read [%s] col[%s] error", this.m_FileName, datacol))
return this.m_S8
}

func (this *RData) Int16(dataname, datacol string) int16{
IFAssert(this.m_Type == DType_S16, fmt.Sprintf("read [%s] col[%s] error", dataname, datacol))
func (this *RData) Int16(datacol string) int16{
IFAssert(this.m_Type == DType_S16, fmt.Sprintf("read [%s] col[%s] error", this.m_FileName, datacol))
return this.m_S16
}

func (this *RData) Int(dataname, datacol string) int{
IFAssert(this.m_Type == DType_S32, fmt.Sprintf("read [%s] col[%s] error", dataname, datacol))
func (this *RData) Int(datacol string) int{
IFAssert(this.m_Type == DType_S32, fmt.Sprintf("read [%s] col[%s] error", this.m_FileName, datacol))
return this.m_S32
}

func (this *RData) Float32(dataname, datacol string) float32{
IFAssert(this.m_Type == DType_F32, fmt.Sprintf("read [%s] col[%s] error", dataname, datacol))
func (this *RData) Float32(datacol string) float32{
IFAssert(this.m_Type == DType_F32, fmt.Sprintf("read [%s] col[%s] error", this.m_FileName, datacol))
return this.m_F32
}

func (this *RData) Float64(dataname, datacol string) float64{
IFAssert(this.m_Type == DType_F64, fmt.Sprintf("read [%s] col[%s] error", dataname, datacol))
func (this *RData) Float64(datacol string) float64{
IFAssert(this.m_Type == DType_F64, fmt.Sprintf("read [%s] col[%s] error", this.m_FileName, datacol))
return this.m_F64
}

func (this *RData) Int64(dataname, datacol string) int64{
IFAssert(this.m_Type == DType_S64, fmt.Sprintf("read [%s] col[%s] error", dataname, datacol))
func (this *RData) Int64(datacol string) int64{
IFAssert(this.m_Type == DType_S64, fmt.Sprintf("read [%s] col[%s] error", this.m_FileName, datacol))
return this.m_S64
}

func (this *RData) StringArray(dataname, datacol string) []string{
IFAssert(this.m_Type == DType_StringArray, fmt.Sprintf("read [%s] col[%s] error", dataname, datacol))
func (this *RData) StringArray(datacol string) []string{
IFAssert(this.m_Type == DType_StringArray, fmt.Sprintf("read [%s] col[%s] error", this.m_FileName, datacol))
return this.m_StringArray
}

func (this *RData) Int8Array(dataname, datacol string) []int8{
IFAssert(this.m_Type == DType_S8Array, fmt.Sprintf("read [%s] col[%s] error", dataname, datacol))
func (this *RData) Int8Array(datacol string) []int8{
IFAssert(this.m_Type == DType_S8Array, fmt.Sprintf("read [%s] col[%s] error", this.m_FileName, datacol))
return this.m_S8Array
}

func (this *RData) Int16Array(dataname, datacol string) []int16{
IFAssert(this.m_Type == DType_S16Array, fmt.Sprintf("read [%s] col[%s] error", dataname, datacol))
func (this *RData) Int16Array(datacol string) []int16{
IFAssert(this.m_Type == DType_S16Array, fmt.Sprintf("read [%s] col[%s] error", this.m_FileName, datacol))
return this.m_S16Array
}

func (this *RData) IntArray(dataname, datacol string) []int{
IFAssert(this.m_Type == DType_S32Array, fmt.Sprintf("read [%s] col[%s] error", dataname, datacol))
func (this *RData) IntArray(datacol string) []int{
IFAssert(this.m_Type == DType_S32Array, fmt.Sprintf("read [%s] col[%s] error", this.m_FileName, datacol))
return this.m_S32Array
}

func (this *RData) Float32Array(dataname, datacol string) []float32{
IFAssert(this.m_Type == DType_F32Array, fmt.Sprintf("read [%s] col[%s] error", dataname, datacol))
func (this *RData) Float32Array(datacol string) []float32{
IFAssert(this.m_Type == DType_F32Array, fmt.Sprintf("read [%s] col[%s] error", this.m_FileName, datacol))
return this.m_F32Array
}

func (this *RData) Float64Array(dataname, datacol string) []float64{
IFAssert(this.m_Type == DType_F64Array, fmt.Sprintf("read [%s] col[%s] error", dataname, datacol))
func (this *RData) Float64Array(datacol string) []float64{
IFAssert(this.m_Type == DType_F64Array, fmt.Sprintf("read [%s] col[%s] error", this.m_FileName, datacol))
return this.m_F64Array
}

func (this *RData) Int64Array(dataname, datacol string) []int64{
IFAssert(this.m_Type == DType_S64Array, fmt.Sprintf("read [%s] col[%s] error", dataname, datacol))
func (this *RData) Int64Array(datacol string) []int64{
IFAssert(this.m_Type == DType_S64Array, fmt.Sprintf("read [%s] col[%s] error", this.m_FileName, datacol))
return this.m_S64Array
}
26 changes: 21 additions & 5 deletions server/client/EventProcess.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"gonet/network"
"gonet/rpc"
"gonet/server/message"
"gonet/server/zone/game/lmath"
"sync/atomic"
)

Expand All @@ -22,6 +23,8 @@ type (
AccountName string
PassWd string
SimId int64
Pos lmath.Point3F
Rot lmath.Point3F
m_Dh base.Dh
}

Expand Down Expand Up @@ -70,13 +73,14 @@ func (this *EventProcess) PacketFunc(socketid uint32, buff []byte) bool {

func (this *EventProcess) Init(num int) {
this.Actor.Init(num)
this.Pos = lmath.Point3F{1, 1, 1}
this.m_Dh.Init()
this.RegisterCall("W_C_SelectPlayerResponse", func(ctx context.Context, packet *message.W_C_SelectPlayerResponse) {
this.AccountId = packet.GetAccountId()
nLen := len(packet.GetPlayerData())
//fmt.Println(len(packet.PlayerData), this.AccountId, packet.PlayerData)
if nLen == 0{
packet1 := &message.C_W_CreatePlayerRequest{PacketHead:message.BuildPacketHead( this.AccountId, rpc.SERVICE_GATESERVER),
packet1 := &message.C_W_CreatePlayerRequest{PacketHead: message.BuildPacketHead( this.AccountId, rpc.SERVICE_GATESERVER),
PlayerName:"我是大坏蛋",
Sex:int32(0),}
this.SendPacket(packet1)
Expand All @@ -102,9 +106,11 @@ func (this *EventProcess) Init(num int) {

this.RegisterCall("A_C_LoginResponse", func(ctx context.Context, packet *message.A_C_LoginResponse) {
if packet.GetError() == base.ACCOUNT_NOEXIST {
packet1 := &message.C_A_RegisterRequest{PacketHead:message.BuildPacketHead( 0, rpc.SERVICE_GATESERVER),
packet1 := &message.C_A_RegisterRequest{PacketHead: message.BuildPacketHead( 0, rpc.SERVICE_GATESERVER),
AccountName: packet.AccountName, Password:this.PassWd}
this.SendPacket(packet1)
}else if packet.GetError() == base.PASSWORD_ERROR{
fmt.Println("账号【",packet.GetAccountName(), "】密码错误")
}
})

Expand All @@ -121,6 +127,8 @@ func (this *EventProcess) Init(num int) {
//map
this.RegisterCall("Z_C_LoginMap", func(ctx context.Context, packet *message.Z_C_LoginMap) {
this.SimId = packet.GetId()
this.Pos = lmath.Point3F{packet.GetPos().GetX(), packet.GetPos().GetY(), packet.GetPos().GetZ()}
this.Rot = lmath.Point3F{0, 0, packet.GetRotation()}
//fmt.Println("login map")
})

Expand All @@ -135,6 +143,8 @@ func (this *EventProcess) Init(num int) {
}
if v.Move != nil{
if v.Id == this.SimId{
this.Pos = lmath.Point3F{v.Move.GetPos().GetX(), v.Move.GetPos().GetY(), v.Move.GetPos().GetZ()}
this.Rot = lmath.Point3F{0, 0, v.Move.GetRotation()}
}
fmt.Printf("Z_C_ENTITY_MOVE :[%d], Pos:[x:%f, y:%f, z:%f], Rot[%f]\n", v.GetId(), v.Move.GetPos().GetX(), v.Move.GetPos().GetY(), v.Move.GetPos().GetZ(), v.Move.GetRotation())
}
Expand All @@ -144,7 +154,7 @@ func (this *EventProcess) Init(num int) {
}

func (this *EventProcess) LoginGame(){
packet1 := &message.C_W_Game_LoginRequset{PacketHead:message.BuildPacketHead( this.AccountId, rpc.SERVICE_GATESERVER),
packet1 := &message.C_W_Game_LoginRequset{PacketHead: message.BuildPacketHead( this.AccountId, rpc.SERVICE_GATESERVER),
PlayerId:this.PlayerId,}
this.SendPacket(packet1)
}
Expand All @@ -155,7 +165,7 @@ var(

func (this *EventProcess) LoginAccount() {
id := atomic.AddInt32(&id, 1)
this.AccountName = fmt.Sprintf("test%d", id)
this.AccountName = fmt.Sprintf("test32%d", id)
this.PassWd = base.MD5(ToSlat(this.AccountName, "123456"))
//this.AccountName = fmt.Sprintf("test%d", base.RAND.RandI(0, 7000))
packet1 := &message.C_A_LoginRequest{PacketHead: message.BuildPacketHead(0, rpc.SERVICE_GATESERVER),
Expand All @@ -171,4 +181,10 @@ func (this *EventProcess) LoginGate() {

var(
PACKET *EventProcess
)
)

func (this *EventProcess) Move(yaw float32, time float32) {
packet1 := &message.C_Z_Move{PacketHead: message.BuildPacketHead(this.AccountId, rpc.SERVICE_GATESERVER),
Move: &message.C_Z_Move_Move{Mode: 0, Normal:&message.C_Z_Move_Move_Normal{Pos:&message.Point3F{X:this.Pos.X, Y:this.Pos.Y, Z:this.Pos.Z}, Yaw:yaw, Duration:time}}}
this.SendPacket(packet1)
}
1 change: 1 addition & 0 deletions server/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func main() {
}

InitCmd()

//PACKET.LoginGame()
//for{
// PACKET.LoginGate()
Expand Down
4 changes: 2 additions & 2 deletions server/world/data/BanData.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package data

import (
"gonet/common"
"gonet/base"
"gonet/common"
"log"
"strings"
)
Expand Down Expand Up @@ -35,7 +35,7 @@ func (this *BanDataRes) Read() bool {
pData := BanData{}

file.GetData(lineData)
pData.BanName = lineData.String("BanWord.dat","BanName" )
pData.BanName = lineData.String("BanName" )
if pData.BanName == ""{
continue
}
Expand Down

0 comments on commit 960fb92

Please sign in to comment.