Esempio n. 1
0
        public override void processMessage(MessageArrivedEventArgs messageArgs)
        {
            User user;

            // zaten login olmus biri tekrar login olmaya calismasin sakin
            if (Game.clientUserMap.TryGetValue(messageArgs.sender, out user) == false)
            {
                RawMessage message = messageArgs.message;

                if (message != null && message.containsField("username"))
                {
                    string username = message.getUTF8String("username");

                    if (username.StartsWith("ArenaSize:"))
                    {
                        int size = int.Parse(username.Split(':')[1]);
                        Game.queue.maxUserCount = Math.Max(2, size);

                        OM_LoginResult.SendMessage(messageArgs.sender, false);
                    }
                    else
                    {
                        user = new User(messageArgs.sender, username);
                        Game.clientUserMap.Add(messageArgs.sender, user);

                        OM_LoginResult.SendMessage(messageArgs.sender, true, user);
                    }
                }
            }
        }
Esempio n. 2
0
        public static void Run()
        {
            Chronos.setInterval(50);      // sunucu dongusunu her 50 milisaniyede tamamlayacak.

            while (true)
            {
                try
                {
                    while (true)
                    {
                        Chronos.waitForTheRightMoment();    // fps yi ayarliyor.
                        frameNumber++;

                        Client client;

                        while (justLeftClients.TryDequeue(out client))
                        {
                            if (clientUserMap.ContainsKey(client))
                            {
                                clientUserMap.Remove(client);
                            }
                            if (clientPlayerMap.ContainsKey(client))
                            {
                                clientPlayerMap.Remove(client);
                            }
                        }

                        //var tmp = arrivedMessages;  // mesajlari alip queue'ya atan koda yeni bir concurrentQueue verelim. o onu doldururken biz bunu bosaltalim.
                        //Interlocked.Exchange<ConcurrentQueue<MessageArrivedEventArgs>>(ref arrivedMessages, tmpArrivedMessages);    // TODO buranin fail olmayacagina emin ol.
                        //tmpArrivedMessages = tmp;
                        tmpArrivedMessages = arrivedMessages;

                        int maxMessagesPerIteration = 50;
                        MessageArrivedEventArgs messageArgs;
                        while (tmpArrivedMessages.TryDequeue(out messageArgs) && maxMessagesPerIteration-- > 0)
                        {
                            RawMessage message = messageArgs.message;
                            if (message.containsField("messageTypeId") == false)
                            {
                                continue;
                            }

                            IIncomingMessage incomingMessage;
                            if (TypeIdGenerator.incomingMessageIds.TryGetValue(message.getInt("messageTypeId"), out incomingMessage))
                            {
                                //Console.WriteLine(incomingMessage.GetType().Name);
                                incomingMessage.processMessage(messageArgs);
                            }
                        }

                        foreach (var arena in arenas)
                        {
                            arena.Update();
                        }
                        arenas.RemoveAll(a => a.awaitsDestruction);

                        queue.Update();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString() + "\nStack Trace:\n" + e.StackTrace);
                }
            }
        }