MCPcopy Create free account
hub / github.com/MonaSolutions/MonaServer / messageHandler

Method messageHandler

MonaCore/sources/FlashMainStream.cpp:55–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55void FlashMainStream::messageHandler(const string& name,AMFReader& message,FlashWriter& writer) {
56 if(name=="connect") {
57 message.stopReferencing();
58
59
60 ParameterWriter parameterWriter(peer.properties());
61
62 if(message.read(AMFReader::OBJECT,parameterWriter)) {
63
64 if (peer.properties().getString("tcUrl",_buffer)) {
65 string serverAddress;
66 Util::UnpackUrl(_buffer, serverAddress,(string&)peer.path,(string&)peer.query);
67 peer.setServerAddress(serverAddress);
68 Util::UnpackQuery(peer.query, peer.properties());
69 }
70
71 if (peer.properties().getNumber<UInt32,3>("objectEncoding")==0) {
72 writer.amf0 = true;
73 WARN("Client ",peer.protocol," not compatible with AMF3, few complex object can be not supported");
74 }
75 }
76
77 message.startReferencing();
78
79
80 // Check if the client is authorized
81 AMFWriter& response = writer.writeAMFSuccess("NetConnection.Connect.Success","Connection succeeded",true);
82 response.amf0 = true;
83 response.writeNumberProperty("objectEncoding",writer.amf0 ? 0.0 : 3.0);
84 response.amf0 = writer.amf0;
85 Exception ex;
86 peer.onConnection(ex, writer,message,response);
87 if (ex) {
88 switch(ex.code()) {
89 case Exception::SOFTWARE:
90 writer.writeAMFError("NetConnection.Connect.Rejected",ex.error());
91 break;
92 case Exception::APPLICATION:
93 writer.writeAMFError("NetConnection.Connect.InvalidApp",ex.error());
94 break;
95 default:
96 writer.writeAMFError("NetConnection.Connect.Failed",ex.error());
97 }
98 writer.writeInvocation("close");
99 writer.close();
100 return;
101 }
102
103 response.endObject();
104
105 } else if(name == "setPeerInfo") {
106
107 peer.localAddresses.clear();
108 while(message.available()) {
109 SocketAddress address;
110 Exception ex;
111 _buffer.clear();
112 if (!message.readString(_buffer) || _buffer.empty())

Callers

nothing calls this directly

Calls 15

stopReferencingMethod · 0.80
setServerAddressMethod · 0.80
startReferencingMethod · 0.80
writeNumberPropertyMethod · 0.80
codeMethod · 0.80
errorMethod · 0.80
readStringMethod · 0.80
readMethod · 0.45
getStringMethod · 0.45
onConnectionMethod · 0.45
closeMethod · 0.45
endObjectMethod · 0.45

Tested by

no test coverage detected