Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright (C) Paul Becker, - All Rights Reserved
- // Unauthorized copying of this file, via any medium is strictly prohibited
- // Proprietary and confidential
- // Written by Paul Becker <paul.becker1@gmx.de>, 22:06
- #region usings
- using System;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.Net.Sockets;
- using System.Threading;
- using SeraphimServer.Logging;
- #endregion
- namespace SeraphimServer.Network
- {
- public class NetworkService
- {
- private static ServerListener _listener;
- private static readonly List<int> ReconnectingAccounts = new List<int>();
- public static int PktCounter;
- public static Connection CnxPreAlloc;
- public static ConcurrentDictionary<int, Connection> Clients = new ConcurrentDictionary<int, Connection>();
- private static int _conId;
- public static void Start()
- {
- PacketHolder.Load();
- Log.Info("PacketHolder loaded");
- _listener = new ServerListener();
- _listener.Start();
- BeginAccept();
- Log.Info("NetworkService - UP!");
- }
- private static void BeginAccept()
- {
- CnxPreAlloc = new Connection(null);
- _listener.BeginAcceptTcpClient(EndAccept, _listener);
- }
- private static void EndAccept(IAsyncResult ar)
- {
- var lsn = (TcpListener) ar.AsyncState;
- var client = lsn.EndAcceptTcpClient(ar);
- CnxPreAlloc.SetClient(client);
- CnxPreAlloc.OnConnect();
- Interlocked.Increment(ref _conId);
- CnxPreAlloc.ConId = _conId;
- Clients.TryAdd(_conId, CnxPreAlloc);
- Log.SystemInfo(String.Format("NetworkService -> Added LClient [List Size = {0}]", Clients.Count));
- BeginAccept();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement