/* Thor Server 2.0 Project - Codenamed "Stockholm" Copyright 2008 - 2009 Joe Hegarty This file is part of The Thor Server 2.0 Project - Codenamed "Stockholm". The Thor Server 2.0 Project - Codenamed "Stockholm" is free software: you can redistribute it and/or modify it under the terms of the Microsoft Public License The Thor Server Project is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Microsoft Public License for more details. You should have received a copy of the Microsoft Public License along with The Thor Server Project. If not, see http://www.opensource.org/licenses/ms-pl.html */ using System; using System.Collections.Generic; using StockholmLibrary.Game.Flats; using StockholmLibrary.Game.Sessions; using StockholmLibrary.Game.Packets.Client; using StockholmLibrary.Game.Packets.Server; using StockholmLibrary.Net; namespace StockholmLibrary.Game.Entities.Components { //------------------------------------ public enum EChatType { SAY, SHOUT, WHISPER } //------------------------------------ public class ECChat : EntityComponentRoomChild { //********************************************** public override void FlatInitiailise(Flat flat) { } //********************************************** public override void FlatDeinitiailise(Flat flat) { } //********************************************** public override void UserInitiailise(Session userSession) { RegisterSessionHandler(userSession, EClientPacket.SAY, new PacketRoutingInfo.ProcessPacketDelegate(HandleSay)); RegisterSessionHandler(userSession, EClientPacket.SHOUT, new PacketRoutingInfo.ProcessPacketDelegate(HandleShout)); RegisterSessionHandler(userSession, EClientPacket.WHISPER, new PacketRoutingInfo.ProcessPacketDelegate(HandleWhisper)); } //********************************************** public override void UserDeinitiailise(Session userSession) { CleanupSessionHandlers(userSession); } //********************************************** private void HandleSay(ClientPacket packet) { SayPacket chatPacket = new SayPacket(); chatPacket.Deserialise(packet); CreateChat(chatPacket.Text, EChatType.SAY); } //********************************************** private void HandleShout(ClientPacket packet) { ShoutPacket chatPacket = new ShoutPacket(); chatPacket.Deserialise(packet); CreateChat(chatPacket.Text, EChatType.SHOUT); } //********************************************** private void HandleWhisper(ClientPacket packet) { WhisperPacket chatPacket = new WhisperPacket(); chatPacket.Deserialise(packet); ECCreatureCollection ecCreatureCollection = null; if (GetRoomEntity().GetEC(ref ecCreatureCollection)) { int creatureId = ecCreatureCollection.GetCreatureIDByECName(chatPacket.Name); CreateChat(chatPacket.Text, EChatType.WHISPER, creatureId); } } //********************************************** public void CreateChat(string text, EChatType chatType, int targetCreature = -1) { text = Stockholm.Get().GameManager.InputFiltering.FilterChat(text); int creatureId = -1; ECCreature ecCreature = new ECCreature(); if (GetParentEntity().GetEC(ref ecCreature)) { creatureId = ecCreature.ID; } dynamic packet; switch (chatType) { case EChatType.SAY: { packet = new ServerSayPacket(creatureId, text); } break; case EChatType.SHOUT: { packet = new ServerShoutPacket(creatureId, text); } break; case EChatType.WHISPER: { packet = new ServerWhisperPacket(creatureId, text); } break; default: packet = null; break; } if (targetCreature == -1) { SendToAllCreatureSessions(packet); } else { ECCreatureCollection ecCreatureCollection = null; if (GetRoomEntity().GetEC(ref ecCreatureCollection)) { Entity creature = ecCreatureCollection.GetCreatureByID(targetCreature); SendToCreatureSession(creature, packet); SendToLocalSession(packet); } } } } }