Changeset - r18745:f30e2b3b8a58
[Not reviewed]
master
0 6 0
truebrain - 13 years ago 2011-12-19 20:50:44
truebrain@openttd.org
(svn r23603) -Add: support for control commands in strings, in both network and safe/load (Rubidium)
6 files changed with 20 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/command_type.h
Show inline comments
 
@@ -355,6 +355,7 @@ enum CommandFlags {
 
	CMD_NO_WATER  = 0x040, ///< set the DC_NO_WATER flag on this command
 
	CMD_CLIENT_ID = 0x080, ///< set p2 with the ClientID of the sending client.
 
	CMD_DEITY     = 0x100, ///< the command may be executed by COMPANY_DEITY
 
	CMD_STR_CTRL  = 0x200, ///< the command's string may contain control strings
 
};
 
DECLARE_ENUM_AS_BIT_SET(CommandFlags)
 

	
src/network/network_command.cpp
Show inline comments
 
@@ -294,16 +294,16 @@ const char *NetworkGameSocketHandler::Re
 
{
 
	cp->company = (CompanyID)p->Recv_uint8();
 
	cp->cmd     = p->Recv_uint32();
 
	if (!IsValidCommand(cp->cmd))               return "invalid command";
 
	if (GetCommandFlags(cp->cmd) & CMD_OFFLINE) return "offline only command";
 
	if ((cp->cmd & CMD_FLAGS_MASK) != 0)        return "invalid command flag";
 

	
 
	cp->p1      = p->Recv_uint32();
 
	cp->p2      = p->Recv_uint32();
 
	cp->tile    = p->Recv_uint32();
 
	p->Recv_string(cp->text, lengthof(cp->text));
 
	p->Recv_string(cp->text, lengthof(cp->text), (!_network_server && GetCommandFlags(cp->cmd) & CMD_STR_CTRL) != 0 ? SVS_ALLOW_CONTROL_CODE | SVS_REPLACE_WITH_QUESTION_MARK : SVS_REPLACE_WITH_QUESTION_MARK);
 

	
 
	byte callback = p->Recv_uint8();
 

	
 
	if (!IsValidCommand(cp->cmd))               return "invalid command";
 
	if (GetCommandFlags(cp->cmd) & CMD_OFFLINE) return "offline only command";
 
	if ((cp->cmd & CMD_FLAGS_MASK) != 0)        return "invalid command flag";
 
	if (callback >= lengthof(_callback_table))  return "invalid callback";
 

	
 
	cp->callback = _callback_table[callback];
src/saveload/saveload.cpp
Show inline comments
 
@@ -1089,7 +1089,14 @@ static void SlString(void *ptr, size_t l
 
			}
 

	
 
			((char *)ptr)[len] = '\0'; // properly terminate the string
 
			str_validate((char *)ptr, (char *)ptr + len);
 
			StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK;
 
			if ((conv & SLF_ALLOW_CONTROL) != 0) {
 
				settings = settings | SVS_ALLOW_CONTROL_CODE;
 
			}
 
			if ((conv & SLF_ALLOW_NEWLINE) != 0) {
 
				settings = settings | SVS_ALLOW_NEWLINE;
 
			}
 
			str_validate((char *)ptr, (char *)ptr + len, settings);
 
			break;
 
		}
 
		case SLA_PTRS: break;
 
@@ -1442,7 +1449,7 @@ bool SlObjectMember(void *ptr, const Sav
 
					}
 
					break;
 
				case SL_ARR: SlArray(ptr, sld->length, conv); break;
 
				case SL_STR: SlString(ptr, sld->length, conv); break;
 
				case SL_STR: SlString(ptr, sld->length, sld->conv); break;
 
				case SL_LST: SlList(ptr, (SLRefType)conv); break;
 
				default: NOT_REACHED();
 
			}
src/saveload/saveload.h
Show inline comments
 
@@ -174,7 +174,9 @@ enum VarTypes {
 
	SLF_NOT_IN_SAVE     = 1 <<  8, ///< do not save with savegame, basically client-based
 
	SLF_NOT_IN_CONFIG   = 1 <<  9, ///< do not save to config file
 
	SLF_NO_NETWORK_SYNC = 1 << 10, ///< do not synchronize over network (but it is saved if SLF_NOT_IN_SAVE is not set)
 
	/* 5 more possible flags */
 
	SLF_ALLOW_CONTROL   = 1 << 11, ///< allow control codes in the strings
 
	SLF_ALLOW_NEWLINE   = 1 << 12, ///< allow new lines in the strings
 
	/* 3 more possible flags */
 
};
 

	
 
typedef uint32 VarType;
src/string.cpp
Show inline comments
 
@@ -207,7 +207,7 @@ void str_validate(char *str, const char 
 
		 * characters to be skipped */
 
		if (c == '\0') break;
 

	
 
		if (IsPrintable(c) && (c < SCC_SPRITE_START || c > SCC_SPRITE_END)) {
 
		if ((IsPrintable(c) && (c < SCC_SPRITE_START || c > SCC_SPRITE_END)) || ((settings & SVS_ALLOW_CONTROL_CODE) != 0 && IsInsideMM(c, SCC_CONTROL_START, SCC_CONTROL_END))) {
 
			/* Copy the character back. Even if dst is current the same as str
 
			 * (i.e. no characters have been changed) this is quicker than
 
			 * moving the pointers ahead by len */
src/string_type.h
Show inline comments
 
@@ -49,6 +49,7 @@ enum StringValidationSettings {
 
	SVS_NONE                       = 0,      ///< Allow nothing and replace nothing.
 
	SVS_REPLACE_WITH_QUESTION_MARK = 1 << 0, ///< Replace the unknown/bad bits with question marks.
 
	SVS_ALLOW_NEWLINE              = 1 << 1, ///< Allow newlines.
 
	SVS_ALLOW_CONTROL_CODE         = 1 << 2, ///< Allow the special control codes.
 
};
 
DECLARE_ENUM_AS_BIT_SET(StringValidationSettings);
 

	
0 comments (0 inline, 0 general)