00001
00002
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00031
00032 #ifndef RCSC_PLAYER_FREE_MESSAGE_H
00033 #define RCSC_PLAYER_FREE_MESSAGE_H
00034
00035 #include <rcsc/player/say_message_builder.h>
00036 #include <rcsc/common/audio_memory.h>
00037 #include <rcsc/common/logger.h>
00038 #include <rcsc/common/server_param.h>
00039
00040 #include <string>
00041 #include <iostream>
00042
00043 namespace rcsc {
00044
00045
00050 template < std::size_t LEN >
00051 class FreeMessage
00052 : public SayMessage {
00053 private:
00054
00055 std::string M_message;
00056
00057 public:
00058
00059 FreeMessage( const std::string & msg )
00060 {
00061 M_message = msg;
00062 }
00063
00068 char header() const
00069 {
00070 return static_cast< char >( '0' + LEN );
00071 }
00072
00077 std::size_t length() const
00078 {
00079 return LEN + 1;
00080 }
00081
00087 bool toStr( std::string & to ) const
00088 {
00089 if ( static_cast< int >( to.length() + 1 + LEN )
00090 > ServerParam::i().playerSayMsgSize() )
00091 {
00092 std::cerr << __FILE__ << ':' << __LINE__
00093 << " FreeMessage: over the capacity. message="
00094 << M_message << ". current size = "
00095 << to.length()
00096 << std::endl;
00097 return false;
00098 }
00099
00100 if ( M_message.length() != LEN )
00101 {
00102 std::cerr << __FILE__ << ':' << __LINE__
00103 << " Illegal message length. message="
00104 << M_message << " must be length " << LEN
00105 << std::endl;
00106 return false;
00107 }
00108
00109 to += header();
00110 to += M_message;
00111 return true;
00112 }
00113
00114 };
00115
00116 }
00117
00118 #endif