test
This commit is contained in:
		
							parent
							
								
									8486ef37ac
								
							
						
					
					
						commit
						b4cb5f20d5
					
				@ -56,23 +56,71 @@ type PacketAdminJoin struct {
 | 
			
		||||
	AppVersion string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type PacketAdminServerProtocol struct {
 | 
			
		||||
	Packet
 | 
			
		||||
	ProtocolVersion    uint8
 | 
			
		||||
	FurtherData        bool
 | 
			
		||||
	UpdatePacketType   uint16
 | 
			
		||||
	FrequenciesAllowed uint16
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type PacketAdminServerWelcome struct {
 | 
			
		||||
	Packet
 | 
			
		||||
	ServerName     string
 | 
			
		||||
	OpenTTDVersion string
 | 
			
		||||
	Dedicated      bool
 | 
			
		||||
	MapName        string
 | 
			
		||||
	MapSeed        uint32
 | 
			
		||||
	MapLandscape   uint8
 | 
			
		||||
	MapStartDate   uint32
 | 
			
		||||
	MapX           uint16
 | 
			
		||||
	MapY           uint16
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (p *PacketAdminJoin) Bytes() []byte {
 | 
			
		||||
	buf := new(bytes.Buffer)
 | 
			
		||||
	p.PLength = uint16(len(p.Password) + len(p.AppName) + len(p.AppVersion) + 6)
 | 
			
		||||
 | 
			
		||||
	binary.Write(buf, binary.LittleEndian, p.PLength)
 | 
			
		||||
	logInfoDebug("len : %d", buf.Len())
 | 
			
		||||
	binary.Write(buf, binary.LittleEndian, p.PType)
 | 
			
		||||
	logInfoDebug("len : %d", buf.Len())
 | 
			
		||||
	buf.WriteString(p.Password)
 | 
			
		||||
	buf.WriteByte(0)
 | 
			
		||||
	logInfoDebug("len : %d", buf.Len())
 | 
			
		||||
	buf.WriteString(p.AppName)
 | 
			
		||||
	buf.WriteByte(0)
 | 
			
		||||
	logInfoDebug("len : %d", buf.Len())
 | 
			
		||||
	buf.WriteString(p.AppVersion)
 | 
			
		||||
	buf.WriteByte(0)
 | 
			
		||||
	logInfoDebug("len : %d", buf.Len())
 | 
			
		||||
 | 
			
		||||
	return buf.Bytes()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (p *AdminPacketServerWelcome) Read(b []byte) {
 | 
			
		||||
	r := bufio.NewReader(bytes.NewReader(b))
 | 
			
		||||
	p.ServerName, _ = r.ReadString(0)
 | 
			
		||||
	p.OpenTTDVersion, _ = r.ReadString(0)
 | 
			
		||||
	c, _ := r.ReadByte()
 | 
			
		||||
	p.Dedicated = bool(c)
 | 
			
		||||
	p.MapName, _ = r.ReadString(0)
 | 
			
		||||
	bs := make([]byte, 13)
 | 
			
		||||
	_, _ = r.Read(bs)
 | 
			
		||||
	p.MapSeed = binary.LittleEndian.Uint32(bs[0:])
 | 
			
		||||
	p.MapLandscape = uint8(bs[4:1])
 | 
			
		||||
	p.MapStartDate = binary.LittleEndian.Uint32(bs[5:])
 | 
			
		||||
	p.MapX = binary.LittleEndian.Uint16(bs[9:])
 | 
			
		||||
	p.MapY = binary.LittleEndian.Uint16(bs[11:])
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func handlePacket(p Packet, b []byte) {
 | 
			
		||||
	switch p.PType {
 | 
			
		||||
	case AdminPacketServerProtocol:
 | 
			
		||||
	case AdminPacketServerWelcome:
 | 
			
		||||
		sp := PacketAdminServerWelcome{
 | 
			
		||||
			PLength: p.PLength,
 | 
			
		||||
			PType:   p.PType,
 | 
			
		||||
		}
 | 
			
		||||
		sp.Read(b)
 | 
			
		||||
		logInfoDebug("AdminPacketServerWelcome : %v", sp)
 | 
			
		||||
	default:
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user