// Initializes the network transport and builds the _channel array. // Returns null on failure, and sets error string with description. protected ConnectionConfig InitializeNetwork( out string error ) { _maxEventCount = _commonSettings.maxEventCount > 0 ? _commonSettings.maxEventCount : UInt32.MaxValue; GlobalConfig gConfig = new GlobalConfig(); // default settings gConfig.MaxPacketSize = _commonSettings.messageBufferSize; NetworkTransport.Init(); ConnectionConfig config = new ConnectionConfig(); config.SendDelay = 0; int channelCount = AlpacaConstant.InternalChannelCount + _commonSettings.customChannel.Length; _channel = new Channel[channelCount]; // add internal channels for( int i = 0; i < AlpacaConstant.InternalChannelCount; ++i ) { string name = AlpacaConstant.INTERNAL_CHANNEL_NAME[i]; QosType qos = AlpacaConstant.INTERNAL_CHANNEL_TYPE[i]; int index = config.AddChannel( qos ); if( index != i ) { error = Log.PrefixMessage( string.Format( "Unexpected channel index {0} while attempting to create {1}", index, name ) ); return null; } _channel[i] = new Channel( ChannelIndex.CreateInternal( (InternalChannel)i ), name, qos ); } // add custom channels for( int i = 0; i < _commonSettings.customChannel.Length; ++i ) { CustomChannelSettings c = _commonSettings.customChannel[i]; int index = config.AddChannel( c.type ); int offsetIndex = i + AlpacaConstant.InternalChannelCount; if( index != offsetIndex ) { error = Log.PrefixMessage( string.Format( "Unexpected channel index {0} while attempting to create {1}", index, c.name ) ); return null; } _channel[offsetIndex] = new Channel( ChannelIndex.CreateCustom( (UInt32)i ), c.name, c.type ); } error = ""; return config; }
// PRIVATE // sends an internal message to the server (Alpaca layer) bool SendInternal( InternalMessage message, InternalChannel channel, BitWriter writer, bool sendImmediately, out string error ) { return Send( message, ChannelIndex.CreateInternal(channel), writer, sendImmediately, out error ); }
// sends a custom message to the server via the default channel public bool SendCustomServer( BitWriter writer, bool sendImmediately, out string error ) { return Send( InternalMessage.CustomServer, ChannelIndex.CreateInternal( InternalChannel.ClientReliable ), writer, sendImmediately, out error ); }