/// <summary> /// Handle a database status notification. /// </summary> /// <param name="Message">Supplies the message.</param> /// <param name="Source">Supplies the message sender.</param> private void OnRecvMessageNotifyDatabaseStatus(NetworkMessage Message, GameServer Source) { BufferParser Parser = Message.GetParser(); int SourceServerId = Parser.ReadInt32(); bool DatabaseOnline = (Parser.ReadByte() == 0 ? false : true); Parser.FinishParsing(); if (SourceServerId != Source.ServerId) return; lock (WorldManager) { if (Source.Online) Source.DatabaseOnline = DatabaseOnline; } }
/// <summary> /// Handle a shutdown notification message. /// </summary> /// <param name="Message">Supplies the message.</param> /// <param name="Source">Supplies the message sender.</param> private void OnRecvMessageShutdownNotify(NetworkMessage Message, GameServer Source) { BufferParser Parser = Message.GetParser(); int SourceServerId = Parser.ReadInt32(); Parser.FinishParsing(); if (SourceServerId != Source.ServerId) return; // // Tear down any state between the two servers. // }
/// <summary> /// This routine handles ALFA datagram protocol messages that have been /// received over the network. /// </summary> /// <param name="Data">Supplies the received data payload.</param> /// <param name="Sender">Supplies the sender's address.</param> /// <param name="SenderPort">Supplies the sender's port.</param> public void OnDatagramReceive(byte[] Data, IPAddress Sender, int SenderPort) { NetworkMessage Message = new NetworkMessage(Data, SocketIo.ALFAProtocolMagic, (byte)SocketIo.PROTOCOL_ID.PROTOCOL_DATAGRAM); GameServer SourceServer = LookupServer(Sender, SenderPort); if (SourceServer == null) { lock (WorldManager) { WorldManager.WriteDiagnosticLog(String.Format("ServerNetworkManager.OnDatagramReceive: Received datagram from unknown source {0}:{1}", Sender, SenderPort)); return; } } // // Dispatch the message. // switch ((DATAGRAM_MESSAGE_CMD)Message.GetCommand()) { case DATAGRAM_MESSAGE_CMD.CMD_IPC_WAKE: OnRecvMessageIPCWake(Message, SourceServer); return; case DATAGRAM_MESSAGE_CMD.CMD_SHUTDOWN_NOTIFY: OnRecvMessageShutdownNotify(Message, SourceServer); return; case DATAGRAM_MESSAGE_CMD.CMD_NOTIFY_DATABASE_STATUS: OnRecvMessageNotifyDatabaseStatus(Message, SourceServer); return; } }
/// <summary> /// Handle an IPC wakeup message received. /// </summary> /// <param name="Message">Supplies the message.</param> /// <param name="Source">Supplies the message sender.</param> private void OnRecvMessageIPCWake(NetworkMessage Message, GameServer Source) { BufferParser Parser = Message.GetParser(); int SourceServerId = Parser.ReadInt32(); int DestinationServerId = Parser.ReadInt32(); Parser.FinishParsing(); if (SourceServerId != Source.ServerId || LocalServerId != DestinationServerId) return; // // Signal the world manager that it should break out of the polling // wait and immediately check for new IPC messages that are // available to process. // WorldManager.SignalIPCEventWakeup(); }
/// <summary> /// Send a direct message to a server. Failures are ignored. /// </summary> /// <param name="Message">Supplies the message payload.</param> /// <param name="Server">Supplies the destination server.</param> private void SendMessageToServer(NetworkMessage Message, GameServer Server) { if (!Server.Online) return; try { SendMessageToServer(Message.FinalizeMessage(), Server); } catch { } }