File: _protocol.py

package info (click to toggle)
oolite 1.77.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 41,264 kB
  • ctags: 5,362
  • sloc: objc: 132,090; ansic: 10,457; python: 2,225; sh: 1,325; makefile: 332; perl: 259; xml: 125; php: 5
file content (70 lines) | stat: -rw-r--r-- 2,000 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#
#  _protocol.py
#  ooliteConsoleServer
#
#  Created by Jens Ayton on 2007-11-29.
#  Copyright (c) 2007 Jens Ayton. All rights reserved.
#


"""
Definitions used to implement Oolite debug console protocol.
"""
# See OODebugTCPConsoleProtocol.h for reference.


# Default TCP port
defaultPort				= 8563


# Packet types
requestConnectionPacket			= "Request Connection"
approveConnectionPacket			= "Approve Connection"
rejectConnectionPacket			= "Reject Connection"
closeConnectionPacket			= "Close Connection"
consoleOutputPacket				= "Console Output"
clearConsolePacket				= "Clear Console"
showConsolePacket				= "Show Console"
noteConfigurationPacket			= "Note Configuration"
noteConfigurationChangePacket	= "Note Configuration Change"
performCommandPacket			= "Perform Command"
requestConfigurationValuePacket	= "Request Configuration Packet"
pingPacket						= "Ping"
pongPacket						= "Pong"


# Value keys
packetTypeKey					= "packet type"
protocolVersionKey				= "protocol version"
ooliteVersionKey				= "Oolite version"
messageKey						= "message"
consoleIdentityKey				= "console identity"
colorKeyKey						= "color key"
emphasisRangesKey				= "emphasis ranges"
configurationKey				= "configuration"
removedConfigurationKeysKey		= "removed configuration keys"
configurationKeyKey				= "configuration key"


# Version encoding
def version(fmt, maj, min):
	""" Encode a protocol version """
	return 65536 * fmt + 256 * maj + min

def versionFormat(vers):
	""" return the format component of a protocol version """
	return (vers / 65536) % 256

def versionMajor(vers):
	""" return the major component of a protocol version """
	return (vers / 256) % 256

def versionMinor(vers):
	""" return the minor component of a protocol version """
	return vers % 256

def versionCompatible(myVersion, remoteVersion):
	return versionFormat(remoteVersion) == versionFormat(myVersion) and versionMajor(remoteVersion) <= versionMajor(myVersion)

# Version constants
protocolVersion_1_1_0			= version(1, 1, 0)