public static void HandleSyndicate(Character pUser, MsgSyndicate pMsg)
        {
            if (pUser == null)
                return;

            switch (pMsg.Action)
            {
                #region Info / Refresh

                case SyndicateRequest.SYN_INFO:
                case SyndicateRequest.SYN_REFRESH:
                    {
                        if (pUser.Syndicate == null
                            || pUser.SyndicateMember == null)
                            return;

                        pUser.SyndicateMember.SendSyndicate();

                        MsgDutyMinContri pNewMsg = new MsgDutyMinContri();
                        foreach (var pPos in m_pShowDuty)
                            pNewMsg.Append(pPos, pUser.Syndicate.MinimumDonation(pPos));
                        pUser.Send(pNewMsg);
                        return;
                    }

                #endregion
                #region Bulletin/Announcement

                case SyndicateRequest.SYN_BULLETIN:
                    {
                        if (pUser.Syndicate == null
                            || pUser.SyndicateMember == null)
                            return;

                        if (pUser.SyndicateMember.Position != SyndicateRank.GUILD_LEADER)
                            return;
                        string msg = Encoding.ASCII.GetString(pMsg, 26, pMsg[25]);
                        if (msg.Length > 127)
                            return;
                        pUser.Syndicate.SetAnnouncement(msg);
                        return;
                    }

                #endregion
                #region Donate Silvers

                case SyndicateRequest.SYN_DONATE_SILVERS:
                    {
                        if (pUser.Syndicate == null
                            || pUser.SyndicateMember == null)
                            return;

                        if (pMsg.Param < 10000) // should donate at least 10000 silvers
                            return;

                        if (!pUser.ReduceMoney(pMsg.Param)) // not enough money
                            return;

                        pUser.Syndicate.ChangeFunds((int) pMsg.Param);
                        pUser.SyndicateMember.IncreaseMoney(pMsg.Param);
                        pUser.SyndicateMember.SendSyndicate();
                        pUser.SyndicateMember.SendCharacterInformation();
                        pUser.Syndicate.Send(string.Format(ServerString.STR_SYN_DONATE,
                                pUser.SyndicateMember.GetRankName(), pUser.Name, pMsg.Param));

                        return;
                    }

                #endregion
                #region Donate CPs

                case SyndicateRequest.SYN_DONATE_CONQUER_POINTS:
                    {
                        if (pUser.Syndicate == null
                            || pUser.SyndicateMember == null)
                            return;

                        if (!pUser.ReduceEmoney(pMsg.Param))
                            return;

                        pUser.Syndicate.ChangeEmoneyFunds((int) pMsg.Param);
                        pUser.SyndicateMember.IncreaseEmoney(pMsg.Param);
                        pUser.SyndicateMember.SendSyndicate();
                        pUser.SyndicateMember.SendCharacterInformation();
                        pUser.Syndicate.Send(string.Format(ServerString.STR_SYN_DONATE_EMONEY,
                                pUser.SyndicateMember.GetRankName(), pUser.Name, pMsg.Param));

                        return;
                    }

                #endregion
                #region Promote

                case SyndicateRequest.SYN_PROMOTE:
                    {
                        if (pUser.Syndicate == null
                            || pUser.SyndicateMember == null)
                            return;

                        pUser.SyndicateMember.SendPromotionList();
                        return;
                    }

                #endregion
                #region Paid Promotion

                case SyndicateRequest.SYN_PAID_PROMOTE:
                    {
                        if (pUser.Syndicate == null
                            || pUser.SyndicateMember == null)
                            return;

                        pUser.Syndicate.ProcessPaidPromotion(pMsg, pUser);
                        return;
                    }

                #endregion
                #region Request Promotion

                case SyndicateRequest.SYN_SEND_REQUEST:

                    if (pUser.Syndicate == null
                        || pUser.SyndicateMember == null)
                        return;

                    if (!Enum.IsDefined(typeof(SyndicateRank), (ushort)pMsg.Param))
                        return;

                    var pos = (SyndicateRank)pMsg.Param;

                    SyndicateMember pMember = pUser.Syndicate.Members.Values.FirstOrDefault(x => x.Name == pMsg.Name);
                    if (pMember == null)
                        return;

                    pUser.Syndicate.PromoteMember(pUser, pMember, pos);
                    return;

                #endregion
                #region Join Request

                case SyndicateRequest.SYN_JOIN_REQUEST:
                    {
                        // no syn join guild param: target
                        if (pUser.Syndicate != null || pUser.SyndicateMember != null)
                            return; // already joined

                        Client pTarget;
                        if (!ServerKernel.Players.TryGetValue(pMsg.Param, out pTarget))
                            return;

                        if (pUser.FetchSynInvite(pMsg.Param))
                        {
                            // do join
                            pTarget.Character.Syndicate.AppendMember(pTarget.Character, pUser.Identity, true);
                            pUser.ClearSynInvite();
                        }
                        else
                        {
                            // add join
                            pUser.SetSynJoin(pMsg.Param);
                            pMsg.Param = pUser.Identity;
                            pMsg.RequiredLevel = pUser.Level;
                            pMsg.RequiredMetempsychosis = pUser.Metempsychosis;
                            pMsg.RequiredProfession = pUser.Profession;
                            pTarget.Send(pMsg);
                            pTarget.Character.SendRelation(pUser);
                        }

                        return;
                    }

                #endregion
                #region Invite Request

                case SyndicateRequest.SYN_INVITE_REQUEST:
                    {
                        // syn invite member param: target
                        if (pUser.Syndicate == null || pUser.SyndicateMember == null)
                            return; // no syn

                        Client pTarget;
                        if (!ServerKernel.Players.TryGetValue(pMsg.Param, out pTarget))
                            return; // target not found

                        Character pTargetUser;
                        if (pUser.Syndicate.WaitQueue.TryRemove(pTarget.Character.Identity, out pTargetUser))
                        {
                            // player waiting to join
                            return;
                        }

                        if (pTarget.Character.FetchSynJoin(pUser.Identity))
                        {
                            // player requested to join
                            if (pUser.Syndicate.Members.Count >= 800)
                                return;

                            pUser.Syndicate.AppendMember(pUser, pTarget.Character.Identity, false);
                            pTarget.Character.ClearSynJoin();
                            return;
                        }
                        // inviting player to join
                        pTarget.Character.SetSynInvite(pUser.Identity);
                        pMsg.Param = pUser.Identity;
                        pMsg.RequiredLevel = pUser.Level;
                        pMsg.RequiredMetempsychosis = pUser.Metempsychosis;
                        pMsg.RequiredProfession = pUser.Profession;
                        pTarget.Send(pMsg);
                        pTarget.Character.SendRelation(pUser);
                        return;
                    }

                #endregion
                #region Quit
                case SyndicateRequest.SYN_QUIT:
                {
                    if (pUser.Syndicate == null
                        || pUser.SyndicateMember == null)
                        return;

                    if (pUser.SyndicateRank == SyndicateRank.GUILD_LEADER)
                        return;

                    pUser.Syndicate.QuitSyndicate(pUser);
                    break;
                }
                #endregion
                #region Set Requirements
                case SyndicateRequest.SYN_SET_REQUIREMENTS:
                {
                    if (pUser.Syndicate == null
                        || pUser.SyndicateMember == null)
                        return;

                    if (pUser.SyndicateRank != SyndicateRank.GUILD_LEADER)
                        return;

                    if (pMsg.RequiredProfession > 127)
                        return; // max ^ 6
                    if (pMsg.RequiredMetempsychosis > 2)
                        return;
                    if (pMsg.RequiredLevel > ServerKernel.MAX_UPLEVEL)
                        return;

                    pUser.Syndicate.SetRequirements((byte) pMsg.RequiredProfession,
                        (byte) pMsg.RequiredMetempsychosis,
                        (byte) pMsg.RequiredLevel);
                    break;
                }
                #endregion
                #region Discharge

                case SyndicateRequest.SYN_DISCHARGE:
                case SyndicateRequest.SYN_DISCHARGE2:
                case SyndicateRequest.SYN_DISCHARGE3: // discharge paid promotion
                {
                    if (pUser.Syndicate == null || pUser.SyndicateMember == null)
                        return;

                    Client pClient =
                        ServerKernel.Players.Values.FirstOrDefault(x => x.Character != null && x.Character.Name == pMsg.Name);

                    SyndicateMember pSynMember = null;
                    if (pClient == null)
                    {
                        DB.Entities.DbUser dbUser = Database.Characters.SearchByName(pMsg.Name);
                        if (dbUser == null)
                            return;

                        if (!pUser.Syndicate.Members.TryGetValue(dbUser.Identity, out pSynMember))
                            return;
                    }
                    else
                    {
                        pSynMember = pClient.Character.SyndicateMember;
                    }

                    pUser.Syndicate.DischargeMember(pUser, pSynMember);
                    break;
                }

                #endregion
                #region Ally
                case SyndicateRequest.SYN_ALLIED:
                {
                    if (pUser.Syndicate == null)
                        return;

                    if (pUser.SyndicateRank != SyndicateRank.GUILD_LEADER)
                        return;

                    if (pUser.Syndicate.Allies.Count >= pUser.Syndicate.MaxAllies())
                    {
                        pUser.Send(ServerString.STR_ALLY_FULL);
                        return;
                    }

                    Syndicate pTarget = ServerKernel.Syndicates.Values.FirstOrDefault(x => x.Name == pMsg.Name);
                    if (pTarget == null || pTarget.Deleted)
                    {
                        pUser.Send(ServerString.STR_SYN_NO_EXIST);
                        return;
                    }

                    if (!pTarget.LeaderIsOnline)
                    {
                        pUser.Send(ServerString.STR_SYN_LEADER_NOT_ONLINE);
                        return;
                    }

                    Character pTargetClient = pTarget.LeaderRole;
                    
                    RequestBox pBox = new RequestBox
                    {
                        OwnerIdentity = pUser.SyndicateIdentity,
                        OwnerName = pUser.SyndicateName,
                        ObjectIdentity = pTarget.Identity,
                        ObjectName = pTarget.Name,
                        Type = RequestBoxType.SYNDICATE_ALLY,
                        Message = string.Format("{0} Guild Leader of {1} wants to be your ally. Do you accept?", pUser.Name, pUser.SyndicateName)
                    };
                    pTargetClient.RequestBox = pUser.RequestBox = pBox;
                    pBox.Send(pTargetClient);
                    break;
                }
                #endregion
                #region Remove Ally
                case SyndicateRequest.SYN_NEUTRAL1:
                {
                    if (pUser.Syndicate == null)
                        return;

                    if (pUser.SyndicateRank != SyndicateRank.GUILD_LEADER)
                        return;

                    Syndicate pTarget = ServerKernel.Syndicates.Values.FirstOrDefault(x => x.Name == pMsg.Name);
                    if (pTarget == null || pTarget.Deleted)
                    {
                        pUser.Send(ServerString.STR_SYN_NO_EXIST);
                        return;
                    }

                    pUser.Syndicate.RemoveAlliance(pTarget.Identity);
                    break;
                }
                #endregion
                #region Enemy
                case SyndicateRequest.SYN_ENEMIED:
                {
                    if (pUser.Syndicate == null)
                        return;

                    if (pUser.SyndicateRank != SyndicateRank.GUILD_LEADER)
                        return;

                    if (pUser.Syndicate.Allies.Count >= pUser.Syndicate.MaxEnemies())
                    {
                        pUser.Send(ServerString.STR_ENEMY_FULL);
                        return;
                    }

                    Syndicate pTarget = ServerKernel.Syndicates.Values.FirstOrDefault(x => x.Name == pMsg.Name);
                    if (pTarget == null || pTarget.Deleted)
                    {
                        pUser.Send(ServerString.STR_SYN_NO_EXIST);
                        return;
                    }

                    pUser.Syndicate.AntagonizeSyndicate(pTarget);
                    break;
                }
                #endregion
                #region Peace
                case SyndicateRequest.SYN_NEUTRAL2:
                {
                    if (pUser.Syndicate == null)
                        return;

                    if (pUser.SyndicateRank != SyndicateRank.GUILD_LEADER)
                        return;

                    Syndicate pTarget = ServerKernel.Syndicates.Values.FirstOrDefault(x => x.Name == pMsg.Name);
                    if (pTarget == null || pTarget.Deleted)
                    {
                        pUser.Send(ServerString.STR_SYN_NO_EXIST);
                        return;
                    }

                    pUser.Syndicate.RemoveEnemy(pTarget.Identity);
                    break;
                }
                #endregion
                default:
                    ServerKernel.Log.SaveLog("Missing handler for 1107:" + pMsg.Action, true);
                    return;
            }
        }
        public static void HandleFamily(Character pUser, MsgFamily pMsg)
        {
            // 22 - kick
            // Add Enemy and Add Ally send the family name
            switch (pMsg.Type)
            {
                #region Information
            case FamilyType.INFO:
            {
                if (pUser.Family == null)
                {
                    return;
                }

                pUser.Family.SendFamily(pUser);
                break;
            }

                #endregion
                #region Members List
            case FamilyType.MEMBERS:
            {
                if (pUser.Family == null)
                {
                    return;
                }
                pUser.Family.SendMembers(pUser);
                break;
            }

                #endregion
                #region Announcement
            case FamilyType.ANNOUNCE:
            {
                if (pUser.Family == null)
                {
                    return;
                }
                pMsg.Identity = pUser.FamilyIdentity;
                pMsg.AddString(pUser.Family.Announcement);
                pUser.Send(pMsg);
                break;
            }

                #endregion
                #region Set Announcement
            case FamilyType.SET_ANNOUNCEMENT:
            {
                if (pUser.Family == null)
                {
                    return;
                }

                if (pUser.FamilyPosition != FamilyRank.CLAN_LEADER)
                {
                    return;
                }

                string szAnnounce = pMsg.Announcement;
                if (szAnnounce.Length > 127)
                {
                    szAnnounce = szAnnounce.Substring(0, 127);
                }

                pUser.Family.Announcement = szAnnounce;
                pUser.Send(pMsg);
                break;
            }

                #endregion
                #region My Clan
            case FamilyType.MY_CLAN:
            {
                if (pUser.Family == null)
                {
                    return;
                }

                pUser.Family.SendFamily(pUser);
                pUser.Family.SendOccupation(pUser);
                break;
            }

                #endregion
                #region Dedicate
            case FamilyType.DEDICATE:
            {
                if (pUser.Family == null)
                {
                    return;
                }

                if (!pUser.ReduceMoney(pMsg.Identity, true))
                {
                    return;
                }

                pUser.Family.MoneyFunds     += pMsg.Identity;
                pUser.FamilyMember.Donation += pMsg.Identity;
                pUser.Family.SendFamily(pUser);
                break;
            }

                #endregion
                #region Invite
            case FamilyType.RECRUIT:
            {
                if (pUser.Family == null)
                {
                    return;
                }

                if (pUser.Family.IsFull)
                {
                    return;
                }

                Client pTarget;
                if (!ServerKernel.Players.TryGetValue(pMsg.Identity, out pTarget))
                {
                    return;
                }

                if (pTarget.Character.Family != null)
                {
                    return;
                }

                pMsg.Identity = pUser.Family.Identity;
                pMsg.AddString(pUser.FamilyName);
                pMsg.AddString(pUser.Name);
                pTarget.Send(pMsg);

                pUser.SetFamilyRecruitRequest(pTarget.Character.Identity);
                break;
            }

                #endregion
                #region Accept Invite
            case FamilyType.ACCEPT_RECRUIT:
            {
                if (pUser.Family != null)
                {
                    return;
                }

                Family pFamily;
                if (!ServerKernel.Families.TryGetValue(pMsg.Identity, out pFamily))
                {
                    return;
                }

                if (pFamily.IsFull)
                {
                    return;
                }

                Client pLeaderS;
                if (!ServerKernel.Players.TryGetValue(pFamily.LeaderIdentity, out pLeaderS))
                {
                    return;
                }

                Character pLeader = pLeaderS.Character;
                if (pLeader.FamilyPosition != FamilyRank.CLAN_LEADER)
                {
                    return;
                }

                if (!pLeader.FetchFamilyRecruitRequest(pUser.Identity))
                {
                    return;
                }

                pFamily.AppendMember(pLeader, pUser);
                pLeader.ClearFamilyRecruitRequest();
                break;
            }

                #endregion
                #region Join
            case FamilyType.JOIN:
            {
                if (pUser.Family != null)
                {
                    return;
                }

                Client pTarget;
                if (!ServerKernel.Players.TryGetValue(pMsg.Identity, out pTarget))
                {
                    return;
                }

                if (pTarget.Character.Family == null || pTarget.Character.Family.IsFull)
                {
                    return;
                }

                pMsg.Identity = pUser.Identity;
                pMsg.AddString(pUser.Name);
                pTarget.Send(pMsg);

                pUser.SetFamilyJoinRequest(pTarget.Character.Identity);
                break;
            }

                #endregion
                #region Accept Join
            case FamilyType.ACCEPT_JOIN_REQUEST:
            {
                if (pUser.Family == null || pUser.FamilyPosition != FamilyRank.CLAN_LEADER)
                {
                    return;
                }

                Client pClienTarget;
                if (!ServerKernel.Players.TryGetValue(pMsg.Identity, out pClienTarget))
                {
                    return;
                }

                Character pInvited = pClienTarget.Character;
                if (pInvited.Family != null)
                {
                    return;
                }

                if (!pInvited.FetchFamilyJoinRequest(pUser.Identity))
                {
                    return;
                }

                pUser.Family.AppendMember(pUser, pInvited);
                pInvited.ClearFamilyJoinRequest();
                break;
            }

                #endregion
                #region Quit
            case FamilyType.QUIT:
            {
                if (pUser.Family == null)
                {
                    return;
                }
                if (pUser.FamilyPosition == FamilyRank.CLAN_LEADER)
                {
                    return;
                }
                if (pUser.FamilyPosition == FamilyRank.SPOUSE)
                {
                    return;
                }
                pUser.Family.KickoutMember(pUser.FamilyMember);
                break;
            }

                #endregion
                #region Abdicate
            case FamilyType.TRANSFER_LEADER:
            {
                break;
            }

                #endregion
                #region Kickout
            case (FamilyType)22:
            {
                if (pUser.Family == null || pUser.FamilyPosition != FamilyRank.CLAN_LEADER)
                {
                    return;
                }
                FamilyMember pTarget = null;
                foreach (var client in pUser.Family.Members.Values)
                {
                    if (client.Name == pMsg.Name)
                    {
                        pTarget = client;
                        break;
                    }
                }
                if (pTarget == null || pTarget.Position == FamilyRank.CLAN_LEADER || pTarget.Position == FamilyRank.SPOUSE)
                {
                    return;
                }
                pUser.Family.KickoutMember(pTarget);
                pUser.Family.SendFamily(pUser);
                pUser.Family.SendMembers(pUser);
                break;
            }

                #endregion
                #region Ally
            case FamilyType.ADD_ALLY:
            {
                if (pUser.Family == null)
                {
                    return;
                }
                if (pUser.FamilyPosition != FamilyRank.CLAN_LEADER)
                {
                    return;
                }
                if (pUser.Family.Allies.Count >= 5)
                {
                    return;
                }

                Client pTargetLeader;
                if (!ServerKernel.Players.TryGetValue(pMsg.Identity, out pTargetLeader))
                {
                    return;
                }

                if (pTargetLeader.Character.FamilyPosition != FamilyRank.CLAN_LEADER)
                {
                    return;
                }

                Family pTarget = pTargetLeader.Character.Family;
                if (pTarget == null)
                {
                    return;
                }

                RequestBox pAlly = new RequestBox
                {
                    OwnerIdentity  = pUser.FamilyIdentity,
                    OwnerName      = pUser.FamilyName,
                    ObjectIdentity = pTarget.Identity,
                    ObjectName     = pTarget.Name,
                    Type           = RequestBoxType.FAMILY_ALLY,
                    Message        = string.Format("{0} Leader of the Clan {1} wants to be your ally. Do you accept?", pUser.Name, pUser.FamilyName)
                };
                pUser.RequestBox = pTargetLeader.Character.RequestBox = pAlly;
                pAlly.Send(pTargetLeader.Character);
                break;
            }

                #endregion
                #region Delete Ally
            case FamilyType.DELETE_ALLY:
            {
                break;
            }

                #endregion
                #region Enemy
            case FamilyType.ADD_ENEMY:
            {
                if (pUser.Family == null)
                {
                    return;
                }
                if (pUser.FamilyPosition != FamilyRank.CLAN_LEADER)
                {
                    return;
                }
                if (pUser.Family.Enemies.Count >= 5)
                {
                    return;
                }
                Family pTarget = ServerKernel.Families.Values.FirstOrDefault(x => x.Name == pMsg.Name);
                if (pTarget == null)
                {
                    return;
                }
                pUser.Family.EnemyFamily(pTarget);
                break;
            }

                #endregion
                #region Delete Enemy
            case FamilyType.DELETE_ENEMY:
            {
                break;
            }

                #endregion
            default:
            {
                ServerKernel.Log.SaveLog(string.Format("MsgFamily:Type{0} not handled", pMsg.Type), true, LogType.WARNING);
                GamePacketHandler.Report(pMsg);
                break;
            }
            }
        }