Example #1
0
        public void clientReport(Event ev)
        {
            foreach (Memory mem in ev._Memories)
            {
                string fileName_remote = mem.Name;
                string md5_remote = mem.Value;

                string src = path_cache + fileName_remote;
                if (!md5table.ContainsKey(fileName_remote))
                {
                    fileDeleteFromClient(fileName_remote, ev._Endpoint);
                    continue;
                }
                else
                {
                    if ((string)md5table[fileName_remote] != md5_remote)
                    {
                        fileSendToClient(fileName_remote, ev._Endpoint);
                    }
                }
            }
            foreach (DictionaryEntry de in md5table)
            {

                if (ev._Memories.IndexOf((string)de.Key) < 0)
                {
                    fileSendToClient((string)de.Key, ev._Endpoint);
                }
            }
        }
 private void receiveEvent(Event msg)
 {
     if (!object.Equals(null, this.onReceiveEvent))
     {
         //onReceiveEvent(msg);
         receiveSortQueue.Add(msg);
     }
 }
Example #3
0
 public void freezePlayer()
 {
     this.chat("you are now seated");
     Event outevent = new Event();
     outevent._Keyword = KeyWord.PLAYER_FREEZE;
     outevent._IntendedRecipients = EventTransfer.CLIENTTOCLIENT;
     outboxMessage(this, outevent);
 }
 public void sendEvent(Event ev)
 {
     if (!connected)
     {
         log("not connected");
         return;
     }
     outQueueRoot.Add(ev);
 }
        public override void inbox(ExtraMegaBlob.References.Event ev)
        {
            //ThingReferences.Globals.Instance.Data[];

            if (object.Equals(null, Globals.Instance.Users[ev._Endpoint]))
            {
                Globals.Instance.Users[ev._Endpoint]      = new User();
                Globals.Instance.Users[ev._Endpoint].Name = "User";
            }
            switch (ev._Keyword)
            {
            case KeyWord.EVENT_CHATMESSAGE:
                if (ev._Source_FullyQualifiedName == "ClientMain")
                {
                    string senderName = Globals.Instance.Users[ev._Endpoint].Name;
                    string message    = ev._Memories["text"].Value;
                    log(" >>>> " + senderName + " >>>> " + message);
                    if (message == "/name")
                    {
                        Globals.Instance.Users[ev._Endpoint].Name = ev._Endpoint;
                        break;
                    }
                    if (message.Length > 6)
                    {
                        if (message.Substring(0, 6) == "/name ")
                        {
                            string newname = message.Substring(6, message.Length - 6);
                            newname = newname.Trim();
                            if (newname != "")
                            {
                                Globals.Instance.Users[ev._Endpoint].Name = newname;
                                break;
                            }
                        }
                    }
                    Event outevent = new Event();
                    outevent._Keyword            = KeyWord.EVENT_CHATMESSAGE;
                    outevent._IntendedRecipients = EventTransfer.SERVERTOCLIENT;
                    outevent._Memories           = new Memories();
                    outevent._Memories.Add(new Memory("text", KeyWord.NIL, message, null));
                    outevent._Memories.Add(new Memory("username", KeyWord.NIL, senderName, null));
                    outboxMessage(this, outevent);
                }
                break;

            case KeyWord.CARTESIAN_SECRETPLAYERLOCATION:
                Globals.Instance.Users[ev._Endpoint].Location.x = float.Parse(ev._Memories[KeyWord.CARTESIAN_X].Value);
                Globals.Instance.Users[ev._Endpoint].Location.y = float.Parse(ev._Memories[KeyWord.CARTESIAN_Y].Value);
                Globals.Instance.Users[ev._Endpoint].Location.z = float.Parse(ev._Memories[KeyWord.CARTESIAN_Z].Value);
                break;

            default:
                // log(ev._Keyword + " from " + ev._Source_FullyQualifiedName);
                break;
            }
        }
 private byte[] prepOutgoingEvent(Event ev)
 {
     byte[] data = ev.ToBytes();
     byte[] encrypted = Encryption2.Encrypt(data, Config.rawKey);
     byte[] preamble = BitConverter.GetBytes(encrypted.LongLength);
     byte[] package = new byte[encrypted.Length + 8];
     Buffer.BlockCopy(preamble, 0, package, 0, 8);
     Buffer.BlockCopy(encrypted, 0, package, 8, encrypted.Length);
     return package;
 }
        public override void inbox(ExtraMegaBlob.References.Event ev)
        {
            //ThingReferences.Globals.Instance.Data[];

            if (object.Equals(null, Globals.Instance.Users[ev._Endpoint]))
            {
                Globals.Instance.Users[ev._Endpoint] = new User();
                Globals.Instance.Users[ev._Endpoint].Name = "User";
            }
            switch (ev._Keyword)
            {
                case KeyWord.EVENT_CHATMESSAGE:
                    if (ev._Source_FullyQualifiedName == "ClientMain")
                    {
                        string senderName = Globals.Instance.Users[ev._Endpoint].Name;
                        string message = ev._Memories["text"].Value;
                        log(" >>>> " + senderName + " >>>> " + message);
                        if (message == "/name")
                        {
                            Globals.Instance.Users[ev._Endpoint].Name = ev._Endpoint;
                            break;
                        }
                        if (message.Length > 6)
                        {
                            if (message.Substring(0, 6) == "/name ")
                            {
                                string newname = message.Substring(6, message.Length - 6);
                                newname = newname.Trim();
                                if (newname != "")
                                {
                                    Globals.Instance.Users[ev._Endpoint].Name = newname;
                                    break;
                                }
                            }
                        }
                        Event outevent = new Event();
                        outevent._Keyword = KeyWord.EVENT_CHATMESSAGE;
                        outevent._IntendedRecipients = EventTransfer.SERVERTOCLIENT;
                        outevent._Memories = new Memories();
                        outevent._Memories.Add(new Memory("text", KeyWord.NIL, message, null));
                        outevent._Memories.Add(new Memory("username", KeyWord.NIL, senderName, null));
                        outboxMessage(this, outevent);
                    }
                    break;
                case KeyWord.CARTESIAN_SECRETPLAYERLOCATION:
                    Globals.Instance.Users[ev._Endpoint].Location.x = float.Parse(ev._Memories[KeyWord.CARTESIAN_X].Value);
                    Globals.Instance.Users[ev._Endpoint].Location.y = float.Parse(ev._Memories[KeyWord.CARTESIAN_Y].Value);
                    Globals.Instance.Users[ev._Endpoint].Location.z = float.Parse(ev._Memories[KeyWord.CARTESIAN_Z].Value);
                    break;
                default:
                   // log(ev._Keyword + " from " + ev._Source_FullyQualifiedName);
                    break;
            }
        }
        public override void inbox(ExtraMegaBlob.References.Event ev)
        {
            //ThingReferences.Globals.Instance.Data[];

            switch (ev._Keyword)
            {
            case KeyWord.CARTESIAN_SECRETPLAYERLOCATION:


                References.Vector3 loc = new Vector3(float.Parse(ev._Memories[KeyWord.CARTESIAN_X].Value), float.Parse(ev._Memories[KeyWord.CARTESIAN_Y].Value), float.Parse(ev._Memories[KeyWord.CARTESIAN_Z].Value));
                if (!globals.Users.Contains(ev._Endpoint))
                {
                    globals.Users.Add(new User("", loc, ev._Endpoint));
                    log("adding: " + ev._Endpoint);
                }
                globals.Users[ev._Endpoint].Location = loc;
                broadcastPlayerLocationAllExcept(ev._Endpoint, loc);
                float dist = References.Math.distanceBetweenPythagCartesian(loc, tableLocation);
                log(dist.ToString());
                if (dist < 30f && !globals.Users[ev._Endpoint].inRange)
                {
                    globals.Users[ev._Endpoint].inRange = true;
                    invite(ev._Endpoint);
                }
                if (dist > 30f && globals.Users[ev._Endpoint].inRange)
                {
                    globals.Users[ev._Endpoint].inRange = false;
                }
                break;

            case KeyWord.TONGITS_PLAYER_INVITE_ACCEPTED:
                if (numPlayers < NUMPLRS)
                {
                    numPlayers++;
                    sendPlayerNumber(ev._Endpoint, numPlayers);
                    if (numPlayers == NUMPLRS)
                    {
                        startNewGame();
                    }
                }
                break;

            default:
                //  log(ev._Keyword + " from " + ev._Source_FullyQualifiedName);
                break;
            }
        }
Example #9
0
 public void deleteFile(Event ev)
 {
     string pathRel = ev._Memories["file"].Value;
     string pathAbs = path_cache + pathRel;
     if (File.Exists(pathAbs))
     {
         if (Helpers.isPluginFile(pathRel) && Helpers.isClientPlugin(pathRel))
             _pluginDeleted(pathRel);
         if (Helpers.isTextureFile(pathRel))
             _textureDeleted(pathRel);
         if (Helpers.isMeshFile(pathRel))
             _meshDeleted(pathRel);
         if (Helpers.isSkeletonFile(pathRel))
             _skeletonDeleted(pathRel);
         File.Delete(pathAbs);
     }
     md5table.Remove(pathRel);
     log("deleted: " + pathRel);
 }
Example #10
0
        public override void inbox(ExtraMegaBlob.References.Event ev)
        {
            //MogreFramework.Globals.Instance.Data[];
            switch (ev._Keyword)
            {
            case KeyWord.TONGITS_GAME_STARTING:
                resetPlayer(this.playerNumber);
                //freezePlayer();
                chat("game is starting");
                break;

            case KeyWord.TONGITS_PLAYER_INVITE:
                freezePlayer();
                if (OgreWindow.Instance.AskQuestionBool("Want to join a game of TongIts?"))
                {
                    acceptNewGame();
                }
                unfreezePlayer();
                break;

            case KeyWord.TONGITS_CARD_DECK_PLACE:
                int    playerNumber = int.Parse(ev._Memories[KeyWord.TONGITS_PLAYER_NUMBER].Value);
                string cardName     = ev._Memories[KeyWord.TONGITS_CARD_DATA].Value;
                //chat(string.Format("Placing a Deck Card Player:{0} Card:{1}", ev._Memories[KeyWord.TONGITS_PLAYER_NUMBER].Value, ev._Memories[KeyWord.TONGITS_CARD_DATA].Value));
                placeCard(playerNumber, cardName);
                break;

            case KeyWord.TONGITS_PLAYER_NUMBER:
                playerNumber = int.Parse(ev._Memories[KeyWord.TONGITS_PLAYER_NUMBER].Value);
                break;

            default:
                //log(ev._Keyword + " from " + ev._Source_FullyQualifiedName);
                //log(ev._WhenRcvd.ToString());
                break;
            }
        }
 //to ram
 private void route_toSingleServer(Event ev2)
 {
     string sourceName = ev2._Source_FullyQualifiedName;
     for (int i = 0; i < ServerClasses.Count; i++)
     {
         if (ServerClasses[i] != null)
         {
             string subscribername = ((ServerPlugin)ServerClasses[i]).Name();
             string[] inputwhitelist = ((ServerPlugin)ServerClasses[i]).AllowedInputNames();
             bool found = false;
             foreach (string allowedSubscriber in inputwhitelist)
             {
                 if (sourceName == allowedSubscriber)
                 {
                     found = true;
                 }
             }
             if (found)
             {
                 _toSingleServer(ev2, subscribername);
             }
         }
     }
 }
 private void route_toAllServers(Event ev2)
 {
     for (int i = 0; i < ServerClasses.Count; i++)
     {
         if (ServerClasses[i] != null)
         {
             bool found = false;
             foreach (string allowedSubscriber in ((ServerPlugin)ServerClasses[i]).AllowedInputNames())
             {
                 if (ev2._Source_FullyQualifiedName == allowedSubscriber)
                 {
                     found = true;
                 }
             }
             found = true;//bypass security for now
             if (found)
             {
                 ((ServerPlugin)ServerClasses[i]).inbox(ev2);
             }
         }
     }
 }
Example #13
0
 private void fileSendToClient(string path, string endpoint)
 {
     byte[] bytes = Helpers.compress_gzip(Helpers.getFileBytes(path_cache + "\\" + path));
     Event outevent = new Event();
     outevent._Endpoint = endpoint;
     outevent._Keyword = KeyWord.CACHE_CLIENTUPDATEFILE;
     outevent._Memories = new Memories();
     outevent._Memories.Add(new Memory("file", KeyWord.NIL, path, bytes));
     toclient(outevent);
 }
Example #14
0
 private void toserver(Event ev)
 {
     if (!object.Equals(null, this.route_toserver))
     {
         route_toserver(ev);
     }
 }
Example #15
0
 public void sendReport()
 {
     Event outevent = new Event();
     outevent._Keyword = KeyWord.CACHE_CLIENTREPORT;
     outevent._Memories = new Memories();
     foreach (DictionaryEntry de in md5table)
     {
         outevent._Memories.Add(new Memory((string)de.Key, KeyWord.NIL, (string)de.Value));
     }
     toserver(outevent);
 }
 public override void inbox(Event ev)
 {
     switch (ev._Keyword)
     {
         case KeyWord.EVENT_CHATMESSAGE:
             if (ev._Source_FullyQualifiedName == "SecretServerPlugin")
             {
                 string senderName = ev._Memories["username"].Value;
                 string message = ev._Memories["text"].Value;
                 // log(" >>>> " + senderName + " >>>> " + message);
                 chat("[" + senderName + "]: " + message);
             }
             break;
         default:
             log(ev._Keyword + " from " + ev._Source_FullyQualifiedName);
             //log(ev._WhenRcvd.ToString());
             break;
     }
 }
 public override void inbox(ExtraMegaBlob.References.Event ev)
 {
 }
Example #18
0
 public void sendEventAllExcept(Event ev)
 {
     if (senderDisabled)
     {
         //log("tried to send without a working sender");
         return;
     }
     if (ev._Endpoint == "")
     {
         return;
     }
     else
     {
         string[] endpoints = unique(ev._Endpoint.Split(','));
         foreach (string endp in allEndpoints)
         {
             bool found = false;
             foreach (string endpoint in endpoints)
             {
                 if (endpoint == endp)
                     found = true;
             }
             if (!found)
                 if (null != outQueueRoot[endp])
                     ((ArrayList)outQueueRoot[endp]).Add(ev);
         }
     }
 }
Example #19
0
 public void sendEventFromPlugin(ServerPlugin Sender, Event ev)
 {
     ev._Source_FullyQualifiedName = Sender.Name();
     sendEvent(ev);
 }
Example #20
0
 void plugins_route_toclient(Event msg)
 {
     network.sendEvent(msg);
 }
Example #21
0
 private void network_route_toserver(Event msg)
 {
     plugins.sourceHub(msg, EventTransfer.CLIENTTOSERVER);
     if (msg._Keyword == KeyWord.CACHE_CLIENTREPORT)
     {
         cache.clientReport(msg);
     }
 }
Example #22
0
 void cache_route_toclient(Event ev)
 {
     //network.sendEvent(ev);
     plugins.sourceHub(ev, EventTransfer.SERVERTOCLIENT);
 }
Example #23
0
 private void fileDeleteFromClient(string path, string endpoint)
 {
     Event outevent = new Event();
     outevent._Endpoint = endpoint;
     outevent._Keyword = KeyWord.CACHE_CLIENTDELETEFILE;
     outevent._Memories = new Memories();
     outevent._Memories.Add(new Memory("file", KeyWord.NIL, path));
     toclient(outevent);
 }
Example #24
0
 private void toclient(Event ev)
 {
     if (!object.Equals(null, this.route_toclient))
     {
         route_toclient(ev);
     }
 }
 private void _route_toclient(Event msg)
 {
     if (!object.Equals(null, this.route_toclient))
     {
         route_toclient(msg);
     }
 }
 //to ram
 private void _toSingleServer(Event ev2, string roomName)
 {
     string[] inputNames = ((ServerPlugin)ServerClasses[roomName]).AllowedInputNames();
     bool found = false;
     foreach (string allowedSubscriber in inputNames)
     {
         if (ev2._Source_FullyQualifiedName == allowedSubscriber)
         {
             found = true;
         }
     }
     if (found)
     {
         ((ServerPlugin)ServerClasses[roomName]).inbox(ev2);
     }
 }
Example #27
0
 public void sendEvent(Event ev)
 {
     if (senderDisabled)
     {
         log("tried to send without a working sender");
         return;
     }
     if (ev._Endpoint == "")
     {
         foreach (DictionaryEntry de in outQueueRoot)
         {
             if (null != outQueueRoot[de.Key])
                 ((ArrayList)outQueueRoot[de.Key]).Add(ev);
         }
     }
     else
     {
         string[] endpoints = unique(ev._Endpoint.Split(','));
         foreach (string endp in endpoints)
         {
             if (null != outQueueRoot[endp])
                 ((ArrayList)outQueueRoot[endp]).Add(ev);
         }
     }
 }
Example #28
0
        public override void inbox(ExtraMegaBlob.References.Event ev)
        {
            if (!ready)
            {
                return;
            }
            switch (ev._Keyword)
            {
            case KeyWord.PLAYER_RESET:
                chat("resetting player");

                Quaternion q = new Quaternion(
                    float.Parse(ev._Memories[KeyWord.DATA_QUATERNION_W].Value),
                    float.Parse(ev._Memories[KeyWord.DATA_QUATERNION_X].Value),
                    float.Parse(ev._Memories[KeyWord.DATA_QUATERNION_Y].Value),
                    float.Parse(ev._Memories[KeyWord.DATA_QUATERNION_Z].Value));

                Mogre.Vector3 v = new Mogre.Vector3(
                    float.Parse(ev._Memories[KeyWord.DATA_VECTOR3_X].Value),
                    float.Parse(ev._Memories[KeyWord.DATA_VECTOR3_Y].Value),
                    float.Parse(ev._Memories[KeyWord.DATA_VECTOR3_Z].Value));

                resetPlayer2(v, q);

                break;

            case KeyWord.CMD_GO:
                this.logConsole("parsing coordinates");

                string arguments = ev._Memories[KeyWord.DATA_STRING].Value.Trim();
                if (arguments == "")
                {
                    return;
                }
                //" -63.60852f, 95.18869f, -115.0435f "

                //resetPlayer2(v, q);
                string[]      x = arguments.Split(',');
                int           a = 0;
                Mogre.Vector3 u = new Mogre.Vector3();
                try
                {
                    for (int s = 0; s < x.Length; s++)
                    {
                        string j = x[s].Trim().Replace("f", "");
                        if (j != "")
                        {
                            switch (a)
                            {
                            case 0:
                                u.x = float.Parse(j);
                                a++;
                                break;

                            case 1:
                                u.y = float.Parse(j);
                                a++;
                                break;

                            case 2:
                                u.z = float.Parse(j);
                                a++;
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
                catch
                {
                }
                resetPlayer2(u, nodes["drone"].Orientation);
                this.logConsole("coordinates: " + u.ToString());

                break;

            case KeyWord.PLAYER_FREEZE:
                player_freeze = true;
                break;

            case KeyWord.PLAYER_UNFREEZE:
                player_freeze = false;
                break;

            default:
                break;
            }
        }
Example #29
0
 public void queueEvent(Event ev)
 {
     sendEvent(ev);
 }
Example #30
0
        public void renameFile(Event ev)
        {
            string pathRelOld = ev._Memories["file"].Value;
            string pathRelNew = ev._Memories["newfile"].Value;
            string pathAbsOld = path_cache + pathRelOld;
            string pathAbsNew = path_cache + pathRelNew;
            string md5 = (string)md5table[pathRelOld];

            if (Helpers.isPluginFile(pathRelOld) && Helpers.isClientPlugin(pathRelOld))
                _pluginDeleted(pathRelOld);
            if (Helpers.isPluginFile(pathRelNew) && Helpers.isClientPlugin(pathRelNew))
                _pluginAdded(pathRelNew);

            if (Helpers.isTextureFile(pathRelOld))
                _textureDeleted(pathRelOld);
            if (Helpers.isTextureFile(pathRelNew))
                _textureAdded(pathRelNew);

            if (Helpers.isMeshFile(pathRelOld))
                _meshDeleted(pathRelOld);
            if (Helpers.isMeshFile(pathRelNew))
                _meshAdded(pathRelNew);

            if (Helpers.isSkeletonFile(pathRelOld))
                _skeletonDeleted(pathRelOld);
            if (Helpers.isSkeletonFile(pathRelNew))
                _skeletonAdded(pathRelNew);

            md5table.Remove(pathRelOld);
            md5table.Add(pathRelNew, md5);

            File.Move(pathAbsOld, pathAbsNew);
            log(string.Format("renamed: {0} to {1}", pathRelOld, pathRelNew));
        }
 public void sourceHub(Event ev, EventTransfer transfer)
 {
     string l = "";
     if (transfer == EventTransfer.SERVERTOCLIENT && ev._Endpoint != "")
         l = " -> " + ev._Endpoint;
     log(ev._Keyword.ToString() + " -> " + transfer.ToString() + l);
     switch (transfer)
     {
         case EventTransfer.TRASH:
             return;
         case EventTransfer.CLIENTTOCLIENT:
             return;
         case EventTransfer.CLIENTTOSERVER:
             route_toAllServers(ev);
             return;
         case EventTransfer.SERVERTOCLIENT:
             _route_toclient(ev);
             return;
         case EventTransfer.SERVERTOSERVER:
             return;
     }
 }
Example #32
0
 public void updateFile(Event ev)
 {
     byte[] fileBytes = Helpers.decompress_gzip(ev._Memories["file"].Bytes);
     string pathRel = ev._Memories["file"].Value;
     string pathAbs = path_cache + pathRel;
     string pathDirAbs = Path.GetDirectoryName(pathAbs);
     if (!Directory.Exists(pathDirAbs))
         Directory.CreateDirectory(pathDirAbs);
     FileStream fs = File.Open(pathAbs, FileMode.OpenOrCreate);
     fs.SetLength(0);
     fs.Write(fileBytes, 0, fileBytes.Length);
     fs.Close();
     string md5 = Encryption.md5_file(pathAbs);
     if (md5table.ContainsKey(pathRel))
         if ((string)md5table[pathRel] != md5)
         {
             if (Helpers.isPluginFile(pathRel) && Helpers.isClientPlugin(pathRel))
                 _pluginDeleted(pathRel);
             if (Helpers.isTextureFile(pathRel))
                 _textureDeleted(pathRel);
             if (Helpers.isMeshFile(pathRel))
                 _meshDeleted(pathRel);
             if (Helpers.isSkeletonFile(pathRel))
                 _skeletonDeleted(pathRel);
         }
     if (Helpers.isPluginFile(pathRel) && Helpers.isClientPlugin(pathRel))
         _pluginAdded(pathRel);
     if (Helpers.isTextureFile(pathRel))
         _textureAdded(pathRel);
     if (Helpers.isMeshFile(pathRel))
         _meshAdded(pathRel);
     if (Helpers.isSkeletonFile(pathRel))
         _skeletonAdded(pathRel);
     md5table[pathRel] = md5;
     log("saved: " + pathRel);
 }
 void plugin_onOutboxMessage(ServerPlugin Sender, Event ev)
 {
     ev._Source_FullyQualifiedName = Sender.Name();
     sourceHub(ev, EventTransfer.SERVERTOCLIENT);
 }
 private void sendLocationBeacon(Mogre.Vector3 pos)
 {
     Memories mems = new Memories();
     mems.Add(new Memory("", KeyWord.CARTESIAN_X, pos.x.ToString(), null));
     mems.Add(new Memory("", KeyWord.CARTESIAN_Y, pos.y.ToString(), null));
     mems.Add(new Memory("", KeyWord.CARTESIAN_Z, pos.z.ToString(), null));
     Event ev = new Event();
     ev._Keyword = KeyWord.CARTESIAN_SECRETPLAYERLOCATION;
     ev._Memories = mems;
     ev._IntendedRecipients = EventTransfer.CLIENTTOSERVER;
     base.outboxMessage(this, ev);
     // log("Location: X=" + imAt.x.ToString() + " Y=" + imAt.y.ToString() + " Z=" + imAt.z.ToString());
 }
Example #35
0
 private void fileRenameFromClient(string endpoint, string path, string newpath)
 {
     Event outevent = new Event();
     outevent._Endpoint = endpoint;
     outevent._Keyword = KeyWord.CACHE_CLIENTRENAMEFILE;
     outevent._Memories = new Memories();
     outevent._Memories.Add(new Memory("file", KeyWord.NIL, path));
     outevent._Memories.Add(new Memory("newfile", KeyWord.NIL, newpath));
     toclient(outevent);
 }