Link to home
Start Free TrialLog in
Avatar of Juro Clash
Juro Clash

asked on

Why this error CS1513

Hello I have an error in my code


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using UCS.Core;
using UCS.Core.Network;
using UCS.Core.Threading;
using UCS.Helpers.Binary;
using UCS.Logic;
using UCS.Packets.Messages.Server;

namespace UCS.Packets.Messages.Client
{
    // Packet 14715
    internal class SendGlobalChatLineMessage : Message
    {
        public SendGlobalChatLineMessage(Device device, Reader reader) : base(device, reader)
        {
        }

        public string Message { get; set; }

        internal override void Decode()
        {
            this.Message = this.Reader.ReadString();
        }

        internal override async void Process()
        {
            if (Message.Length > 0 && Message.Length < 200)
            {
                if (Message[0] == '/')
                {
                    object obj = GameOpCommandFactory.Parse(Message);
                    if (obj != null)
                    {
                        string player = "";
                        if (this.Device.Player != null)
                            player += " (" + this.Device.Player.Avatar.UserId + ", " +
                                      this.Device.Player.Avatar.AvatarName + ")";
                        ((GameOpCommand) obj).Execute(this.Device.Player);
                    }
                }
                else
                {
                    long senderId = this.Device.Player.Avatar.UserId;
                    string senderName = this.Device.Player.Avatar.AvatarName;

                    
                    try
                    {
                        
                        {
                            foreach (Level pl in ResourcesManager.m_vOnlinePlayers)
                            {
                                if (pl.Avatar.Region == this.Device.Player.Avatar.Region)
                                {
                                    string NewMessage = "";

                                    for (int i = 0; i < Message.Length; i++){NewMessage += "*";}

                                    GlobalChatLineMessage p = new GlobalChatLineMessage(pl.Client)
                                    {
                                        PlayerName = senderName,
                                        Message = NewMessage,
                                        HomeId = senderId,
                                        CurrentHomeId = senderId,
                                        LeagueId = this.Device.Player.Avatar.m_vLeagueId
                                    };

                                    p.SetAlliance(ObjectManager.GetAlliance(this.Device.Player.Avatar.AllianceId));
                                    p.Send();
                                }
                            }
                        }
                  
                    
                        else
                        {
                            foreach (Level onlinePlayer in ResourcesManager.m_vOnlinePlayers)
                            {
                                if (onlinePlayer.Avatar.Region == this.Device.Player.Avatar.Region)
                                {
                                    GlobalChatLineMessage p = new GlobalChatLineMessage(onlinePlayer.Client)
                                    {
                                        PlayerName = senderName,
                                        Message = this.Message,
                                        HomeId = senderId,
                                        CurrentHomeId = senderId,
                                        LeagueId = this.Device.Player.Avatar.m_vLeagueId
                                    };
                                    p.SetAlliance(ObjectManager.GetAlliance(this.Device.Player.Avatar.AllianceId));
                                    p.Send();
                                    Logger.Write($"Chat Message: '{Message}' from '{senderName}':'{senderId}'");
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
    }
}

Open in new window

Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

something is incorrect with your {}.

Check your "try". You have 2 { and they are not properly closed.
Avatar of Juro Clash
Juro Clash

ASKER

How to close them?
You need to review your code. One thing for sure is that you have a else clause (line 79) and I don't see the if statement that goes with it.
As Eric stated, you are missing your if block (check line 37):
internal class SendGlobalChatLineMessage : Message
{
    public SendGlobalChatLineMessage(Device device, Reader reader) : base(device, reader)
    {
    }

    public string Message { get; set; }

    internal override void Decode()
    {
        this.Message = this.Reader.ReadString();
    }

    internal override async void Process()
    {
        if (Message.Length > 0 && Message.Length < 200)
        {
            if (Message[0] == '/')
            {
                object obj = GameOpCommandFactory.Parse(Message);
                if (obj != null)
                {
                    string player = "";
                    if (this.Device.Player != null)
                        player += " (" + this.Device.Player.Avatar.UserId + ", " +
                                    this.Device.Player.Avatar.AvatarName + ")";
                    ((GameOpCommand)obj).Execute(this.Device.Player);
                }
            }
            else
            {
                long senderId = this.Device.Player.Avatar.UserId;
                string senderName = this.Device.Player.Avatar.AvatarName;

                try
                {
                    if (you need to specify your if portion here)
                    {
                        foreach (Level pl in ResourcesManager.m_vOnlinePlayers)
                        {
                            if (pl.Avatar.Region == this.Device.Player.Avatar.Region)
                            {
                                string NewMessage = "";

                                for (int i = 0; i < Message.Length; i++) { NewMessage += "*"; }

                                GlobalChatLineMessage p = new GlobalChatLineMessage(pl.Client)
                                {
                                    PlayerName = senderName,
                                    Message = NewMessage,
                                    HomeId = senderId,
                                    CurrentHomeId = senderId,
                                    LeagueId = this.Device.Player.Avatar.m_vLeagueId
                                };

                                p.SetAlliance(ObjectManager.GetAlliance(this.Device.Player.Avatar.AllianceId));
                                p.Send();
                            }
                        }
                    }
                    else
                    {
                        foreach (Level onlinePlayer in ResourcesManager.m_vOnlinePlayers)
                        {
                            if (onlinePlayer.Avatar.Region == this.Device.Player.Avatar.Region)
                            {
                                GlobalChatLineMessage p = new GlobalChatLineMessage(onlinePlayer.Client)
                                {
                                    PlayerName = senderName,
                                    Message = this.Message,
                                    HomeId = senderId,
                                    CurrentHomeId = senderId,
                                    LeagueId = this.Device.Player.Avatar.m_vLeagueId
                                };
                                p.SetAlliance(ObjectManager.GetAlliance(this.Device.Player.Avatar.AllianceId));
                                p.Send();
                                Logger.Write($"Chat Message: '{Message}' from '{senderName}':'{senderId}'");
                            }
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
        }
    }
}

Open in new window

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.